Developer Documentation
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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 //================================================================
51 //
52 // CLASS SplatCloud - IMPLEMENTATION
53 //
54 //================================================================
55 
56 
57 //== INCLUDES ====================================================
58 
59 
60 #include "SplatCloud.hh"
61 
62 #include <iostream>
63 
64 
65 //== STATIC MEMBERS ==============================================
66 
67 
68 const SplatCloud::PositionsHandle SplatCloud::POSITIONS_HANDLE ( "<Positions>" );
69 const SplatCloud::ColorsHandle SplatCloud::COLORS_HANDLE ( "<Colors>" );
70 const SplatCloud::NormalsHandle SplatCloud::NORMALS_HANDLE ( "<Normals>" );
71 const SplatCloud::PointsizesHandle SplatCloud::POINTSIZES_HANDLE( "<Pointsizes>" );
72 const SplatCloud::IndicesHandle SplatCloud::INDICES_HANDLE ( "<Indices>" );
73 const SplatCloud::ViewlistsHandle SplatCloud::VIEWLISTS_HANDLE ( "<Viewlists>" );
74 const SplatCloud::SelectionsHandle SplatCloud::SELECTIONS_HANDLE( "<Selections>" );
75 
76 
77 //== IMPLEMENTATION ==============================================
78 
79 
80 void SplatCloud::copySplatProperties( const SplatCloud &_splatCloud )
81 {
82  // deep copy all splat-properties
83  SplatPropertyMap::const_iterator splatPropertyIter;
84  for( splatPropertyIter = _splatCloud.splatProperties_.begin(); splatPropertyIter != _splatCloud.splatProperties_.end(); ++splatPropertyIter )
85  {
86  // create new deep copy of current splat-property
87  SplatPropertyInterface *prop = splatPropertyIter->second.property_->clone();
88 
89  // check if out of memory
90  if( prop == 0 )
91  {
92  std::cerr << "Out of memory for a copy of SplatCloud's splat-property \"" << splatPropertyIter->first << "\"." << std::endl;
93  continue;
94  }
95 
96  // insert new property map entry into splat-property map with same name as before
97  splatProperties_[ splatPropertyIter->first ] = SplatPropertyMapEntry( prop, splatPropertyIter->second.numRequests_ );
98  }
99 
100  // Get pointers to predefined splat-properties.
101  // These can *not* be copied because they have to point to the newly
102  // created deep copies of the properties and not to the old properties.
104 }
105 
106 
107 //----------------------------------------------------------------
108 
109 
110 void SplatCloud::copyCloudProperties( const SplatCloud &_splatCloud )
111 {
112  // deep copy all cloud-properties
113  CloudPropertyMap::const_iterator cloudPropertyIter;
114  for( cloudPropertyIter = _splatCloud.cloudProperties_.begin(); cloudPropertyIter != _splatCloud.cloudProperties_.end(); ++cloudPropertyIter )
115  {
116  // create new deep copy of current cloud-property
117  CloudPropertyInterface *prop = cloudPropertyIter->second.property_->clone();
118 
119  // check if out of memory
120  if( prop == 0 )
121  {
122  std::cerr << "Out of memory for a copy of SplatCloud's cloud-property \"" << cloudPropertyIter->first << "\"." << std::endl;
123  continue;
124  }
125 
126  // insert new property map entry into cloud-property map with same name as before
127  cloudProperties_[ cloudPropertyIter->first ] = CloudPropertyMapEntry( prop, cloudPropertyIter->second.numRequests_ );
128  }
129 
130  // Get pointers to predefined cloud-properties.
131  // These can *not* be copied because they have to point to the newly
132  // created deep copies of the properties and not to the old properties.
134 }
135 
136 
137 //----------------------------------------------------------------
138 
139 
140 SplatCloud::SplatCloud( const SplatCloud &_splatCloud )
141 {
142  // copy number of splats
143  numSplats_ = _splatCloud.numSplats_;
144 
145  // deep copy all properties
146  copySplatProperties( _splatCloud );
147  copyCloudProperties( _splatCloud );
148 }
149 
150 
151 //----------------------------------------------------------------
152 
153 
155 {
156  // free memory of all splat-properties
157  SplatPropertyMap::const_iterator splatPropertyIter;
158  for( splatPropertyIter = splatProperties_.begin(); splatPropertyIter != splatProperties_.end(); ++splatPropertyIter )
159  delete splatPropertyIter->second.property_;
160 
161  // clear splat-property map
163 
164  // reset pointers to predefined splat-properties
166 }
167 
168 
169 //----------------------------------------------------------------
170 
171 
173 {
174  // free memory of all cloud-properties
175  CloudPropertyMap::const_iterator cloudPropertyIter;
176  for( cloudPropertyIter = cloudProperties_.begin(); cloudPropertyIter != cloudProperties_.end(); ++cloudPropertyIter )
177  delete cloudPropertyIter->second.property_;
178 
179  // clear cloud-property map
181 
182  // reset pointers to predefined cloud-properties
184 }
185 
186 
187 //----------------------------------------------------------------
188 
189 
191 {
192  // reset number of splats
193  numSplats_ = 0;
194 
195  // clear all properties
198 }
199 
200 
201 //----------------------------------------------------------------
202 
203 
204 void SplatCloud::swap( SplatCloud &_splatCloud )
205 {
206  // swap number of splats
207  std::swap( numSplats_, _splatCloud.numSplats_ );
208 
209  // swap all properties
210  std::swap( splatProperties_, _splatCloud.splatProperties_ );
211  std::swap( cloudProperties_, _splatCloud.cloudProperties_ );
212 
213  // swap pointers to predefined properties
216 }
217 
218 
219 //----------------------------------------------------------------
220 
221 
223 {
224  // clear data vector of all splat-properties
225  SplatPropertyMap::const_iterator splatPropertyIter;
226  for( splatPropertyIter = splatProperties_.begin(); splatPropertyIter != splatProperties_.end(); ++splatPropertyIter )
227  splatPropertyIter->second.property_->clear();
228 
229  // reset number of splats
230  numSplats_ = 0;
231 }
232 
233 
234 //----------------------------------------------------------------
235 
236 
238 {
239  // add one element at end of data vector of all splat-properties
240  SplatPropertyMap::const_iterator splatPropertyIter;
241  for( splatPropertyIter = splatProperties_.begin(); splatPropertyIter != splatProperties_.end(); ++splatPropertyIter )
242  splatPropertyIter->second.property_->pushback();
243 
244  // increase number of splats
245  ++numSplats_;
246 }
247 
248 
249 //----------------------------------------------------------------
250 
251 
252 void SplatCloud::resizeSplats( unsigned int _num )
253 {
254  // resize data vector of all splat-properties
255  SplatPropertyMap::const_iterator splatPropertyIter;
256  for( splatPropertyIter = splatProperties_.begin(); splatPropertyIter != splatProperties_.end(); ++splatPropertyIter )
257  splatPropertyIter->second.property_->resize( _num );
258 
259  // update number of splats
260  numSplats_ = _num;
261 }
void clearSplatProperties()
Clear all splat-properties.
Definition: SplatCloud.cc:154
void getPredefinedSplatPropertyPointers()
Get pointers to predefined splat-properties.
Definition: SplatCloud.hh:675
std::map< BasePropertyHandle, CloudPropertyMapEntry > CloudPropertyMap
Definition: SplatCloud.hh:281
std::map< BasePropertyHandle, SplatPropertyMapEntry > SplatPropertyMap
Definition: SplatCloud.hh:276
void clear()
Remove all properties and reset the number of splats.
Definition: SplatCloud.cc:190
void clearCloudProperties()
Clear all cloud-properties.
Definition: SplatCloud.cc:172
void resetPredefinedCloudPropertyPointers()
Reset pointers to predefined cloud-properties.
Definition: SplatCloud.hh:672
void swapPredefinedCloudPropertyPointers(SplatCloud &_splatCloud)
Swap pointers to predefined cloud-properties.
Definition: SplatCloud.hh:702
void pushbackSplat()
Add one element at the end of the data vector of all splat-properties.
Definition: SplatCloud.cc:237
void resizeSplats(unsigned int _num)
Resize the data vector of all splat-properties.
Definition: SplatCloud.cc:252
SplatCloud()
Standard constructor.
Definition: SplatCloud.hh:93
void resetPredefinedSplatPropertyPointers()
Reset pointers to predefined splat-properties.
Definition: SplatCloud.hh:660
void swap(SplatCloud &_splatCloud)
Swap the content.
Definition: SplatCloud.cc:204
void getPredefinedCloudPropertyPointers()
Get pointers to predefined cloud-properties.
Definition: SplatCloud.hh:687
CloudPropertyMap cloudProperties_
Cloud-property map.
Definition: SplatCloud.hh:485
unsigned int numSplats_
Number of splats.
Definition: SplatCloud.hh:192
virtual CloudPropertyInterface * clone() const =0
Return a deep copy of this.
SplatPropertyMap splatProperties_
Splat-property map.
Definition: SplatCloud.hh:482
void swapPredefinedSplatPropertyPointers(SplatCloud &_splatCloud)
Swap pointers to predefined splat-properties.
Definition: SplatCloud.hh:690
void clearSplats()
Clear the data vector of all splat-properties.
Definition: SplatCloud.cc:222
virtual SplatPropertyInterface * clone() const =0
Return a deep copy of this.
void copySplatProperties(const SplatCloud &_splatCloud)
Deep copy all splat-properties.
Definition: SplatCloud.cc:80
void copyCloudProperties(const SplatCloud &_splatCloud)
Deep copy all cloud-properties.
Definition: SplatCloud.cc:110