Developer Documentation
Loading...
Searching...
No Matches
SplatCloud.cc
1/*===========================================================================*\
2* *
3* OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39* *
40\*===========================================================================*/
41
42
43
44//================================================================
45//
46// CLASS SplatCloud - IMPLEMENTATION
47//
48//================================================================
49
50
51//== INCLUDES ====================================================
52
53
54#include "SplatCloud.hh"
55
56#include <iostream>
57
58
59//== STATIC MEMBERS ==============================================
60
61
62const SplatCloud::PositionsHandle SplatCloud::POSITIONS_HANDLE ( "<Positions>" );
63const SplatCloud::ColorsHandle SplatCloud::COLORS_HANDLE ( "<Colors>" );
64const SplatCloud::NormalsHandle SplatCloud::NORMALS_HANDLE ( "<Normals>" );
65const SplatCloud::PointsizesHandle SplatCloud::POINTSIZES_HANDLE( "<Pointsizes>" );
66const SplatCloud::IndicesHandle SplatCloud::INDICES_HANDLE ( "<Indices>" );
67const SplatCloud::ViewlistsHandle SplatCloud::VIEWLISTS_HANDLE ( "<Viewlists>" );
68const SplatCloud::SelectionsHandle SplatCloud::SELECTIONS_HANDLE( "<Selections>" );
69
70
71//== IMPLEMENTATION ==============================================
72
73
75{
76 // deep copy all splat-properties
77 SplatPropertyMap::const_iterator splatPropertyIter;
78 for( splatPropertyIter = _splatCloud.splatProperties_.begin(); splatPropertyIter != _splatCloud.splatProperties_.end(); ++splatPropertyIter )
79 {
80 // create new deep copy of current splat-property
81 SplatPropertyInterface *prop = splatPropertyIter->second.property_->clone();
82
83 // check if out of memory
84 if( prop == 0 )
85 {
86 std::cerr << "Out of memory for a copy of SplatCloud's splat-property \"" << splatPropertyIter->first << "\"." << std::endl;
87 continue;
88 }
89
90 // insert new property map entry into splat-property map with same name as before
91 splatProperties_[ splatPropertyIter->first ] = SplatPropertyMapEntry( prop, splatPropertyIter->second.numRequests_ );
92 }
93
94 // Get pointers to predefined splat-properties.
95 // These can *not* be copied because they have to point to the newly
96 // created deep copies of the properties and not to the old properties.
98}
99
100
101//----------------------------------------------------------------
102
103
105{
106 // deep copy all cloud-properties
107 CloudPropertyMap::const_iterator cloudPropertyIter;
108 for( cloudPropertyIter = _splatCloud.cloudProperties_.begin(); cloudPropertyIter != _splatCloud.cloudProperties_.end(); ++cloudPropertyIter )
109 {
110 // create new deep copy of current cloud-property
111 CloudPropertyInterface *prop = cloudPropertyIter->second.property_->clone();
112
113 // check if out of memory
114 if( prop == 0 )
115 {
116 std::cerr << "Out of memory for a copy of SplatCloud's cloud-property \"" << cloudPropertyIter->first << "\"." << std::endl;
117 continue;
118 }
119
120 // insert new property map entry into cloud-property map with same name as before
121 cloudProperties_[ cloudPropertyIter->first ] = CloudPropertyMapEntry( prop, cloudPropertyIter->second.numRequests_ );
122 }
123
124 // Get pointers to predefined cloud-properties.
125 // These can *not* be copied because they have to point to the newly
126 // created deep copies of the properties and not to the old properties.
128}
129
130
131//----------------------------------------------------------------
132
133
135{
136 // copy number of splats
137 numSplats_ = _splatCloud.numSplats_;
138
139 // deep copy all properties
140 copySplatProperties( _splatCloud );
141 copyCloudProperties( _splatCloud );
142}
143
144
145//----------------------------------------------------------------
146
147
149{
150 // free memory of all splat-properties
151 SplatPropertyMap::const_iterator splatPropertyIter;
152 for( splatPropertyIter = splatProperties_.begin(); splatPropertyIter != splatProperties_.end(); ++splatPropertyIter )
153 delete splatPropertyIter->second.property_;
154
155 // clear splat-property map
157
158 // reset pointers to predefined splat-properties
160}
161
162
163//----------------------------------------------------------------
164
165
167{
168 // free memory of all cloud-properties
169 CloudPropertyMap::const_iterator cloudPropertyIter;
170 for( cloudPropertyIter = cloudProperties_.begin(); cloudPropertyIter != cloudProperties_.end(); ++cloudPropertyIter )
171 delete cloudPropertyIter->second.property_;
172
173 // clear cloud-property map
175
176 // reset pointers to predefined cloud-properties
178}
179
180
181//----------------------------------------------------------------
182
183
185{
186 // reset number of splats
187 numSplats_ = 0;
188
189 // clear all properties
192}
193
194
195//----------------------------------------------------------------
196
197
198void SplatCloud::swap( SplatCloud &_splatCloud )
199{
200 // swap number of splats
201 std::swap( numSplats_, _splatCloud.numSplats_ );
202
203 // swap all properties
204 std::swap( splatProperties_, _splatCloud.splatProperties_ );
205 std::swap( cloudProperties_, _splatCloud.cloudProperties_ );
206
207 // swap pointers to predefined properties
210}
211
212
213//----------------------------------------------------------------
214
215
217{
218 // clear data vector of all splat-properties
219 SplatPropertyMap::const_iterator splatPropertyIter;
220 for( splatPropertyIter = splatProperties_.begin(); splatPropertyIter != splatProperties_.end(); ++splatPropertyIter )
221 splatPropertyIter->second.property_->clear();
222
223 // reset number of splats
224 numSplats_ = 0;
225}
226
227
228//----------------------------------------------------------------
229
230
232{
233 // add one element at end of data vector of all splat-properties
234 SplatPropertyMap::const_iterator splatPropertyIter;
235 for( splatPropertyIter = splatProperties_.begin(); splatPropertyIter != splatProperties_.end(); ++splatPropertyIter )
236 splatPropertyIter->second.property_->pushback();
237
238 // increase number of splats
239 ++numSplats_;
240}
241
242
243//----------------------------------------------------------------
244
245
246void SplatCloud::resizeSplats( unsigned int _num )
247{
248 // resize data vector of all splat-properties
249 SplatPropertyMap::const_iterator splatPropertyIter;
250 for( splatPropertyIter = splatProperties_.begin(); splatPropertyIter != splatProperties_.end(); ++splatPropertyIter )
251 splatPropertyIter->second.property_->resize( _num );
252
253 // update number of splats
254 numSplats_ = _num;
255}
virtual CloudPropertyInterface * clone() const =0
Return a deep copy of this.
virtual SplatPropertyInterface * clone() const =0
Return a deep copy of this.
void getPredefinedSplatPropertyPointers()
Get pointers to predefined splat-properties.
void swap(SplatCloud &_splatCloud)
Swap the content.
void copyCloudProperties(const SplatCloud &_splatCloud)
Deep copy all cloud-properties.
void swapPredefinedSplatPropertyPointers(SplatCloud &_splatCloud)
Swap pointers to predefined splat-properties.
void pushbackSplat()
Add one element at the end of the data vector of all splat-properties.
void resizeSplats(unsigned int _num)
Resize the data vector of all splat-properties.
SplatPropertyMap splatProperties_
Splat-property map.
CloudPropertyMap cloudProperties_
Cloud-property map.
void getPredefinedCloudPropertyPointers()
Get pointers to predefined cloud-properties.
void resetPredefinedSplatPropertyPointers()
Reset pointers to predefined splat-properties.
void clearSplats()
Clear the data vector of all splat-properties.
void resetPredefinedCloudPropertyPointers()
Reset pointers to predefined cloud-properties.
std::map< BasePropertyHandle, SplatPropertyMapEntry > SplatPropertyMap
unsigned int numSplats_
Number of splats.
void clearSplatProperties()
Clear all splat-properties.
void clearCloudProperties()
Clear all cloud-properties.
SplatCloud()
Standard constructor.
Definition SplatCloud.hh:87
void copySplatProperties(const SplatCloud &_splatCloud)
Deep copy all splat-properties.
Definition SplatCloud.cc:74
std::map< BasePropertyHandle, CloudPropertyMapEntry > CloudPropertyMap
void swapPredefinedCloudPropertyPointers(SplatCloud &_splatCloud)
Swap pointers to predefined cloud-properties.
void clear()
Remove all properties and reset the number of splats.