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 //================================================================
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
62 const SplatCloud::PositionsHandle SplatCloud::POSITIONS_HANDLE ( "<Positions>" );
63 const SplatCloud::ColorsHandle SplatCloud::COLORS_HANDLE ( "<Colors>" );
64 const SplatCloud::NormalsHandle SplatCloud::NORMALS_HANDLE ( "<Normals>" );
65 const SplatCloud::PointsizesHandle SplatCloud::POINTSIZES_HANDLE( "<Pointsizes>" );
66 const SplatCloud::IndicesHandle SplatCloud::INDICES_HANDLE ( "<Indices>" );
67 const SplatCloud::ViewlistsHandle SplatCloud::VIEWLISTS_HANDLE ( "<Viewlists>" );
68 const SplatCloud::SelectionsHandle SplatCloud::SELECTIONS_HANDLE( "<Selections>" );
69
70
71 //== IMPLEMENTATION ==============================================
72
73
74 void SplatCloud::copySplatProperties( const SplatCloud &_splatCloud )
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.
97 getPredefinedSplatPropertyPointers();
98 }
99
100
101 //----------------------------------------------------------------
102
103
104 void SplatCloud::copyCloudProperties( const SplatCloud &_splatCloud )
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.
127 getPredefinedCloudPropertyPointers();
128 }
129
130
131 //----------------------------------------------------------------
132
133
134 SplatCloud::SplatCloud( const SplatCloud &_splatCloud )
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
148 void SplatCloud::clearSplatProperties()
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
156 SplatPropertyMap().swap( splatProperties_ );
157
158 // reset pointers to predefined splat-properties
159 resetPredefinedSplatPropertyPointers();
160 }
161
162
163 //----------------------------------------------------------------
164
165
166 void SplatCloud::clearCloudProperties()
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
174 CloudPropertyMap().swap( cloudProperties_ );
175
176 // reset pointers to predefined cloud-properties
177 resetPredefinedCloudPropertyPointers();
178 }
179
180
181 //----------------------------------------------------------------
182
183
184 void SplatCloud::clear()
185 {
186 // reset number of splats
187 numSplats_ = 0;
188
189 // clear all properties
190 clearSplatProperties();
191 clearCloudProperties();
192 }
193
194
195 //----------------------------------------------------------------
196
197
198 void 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
208 swapPredefinedSplatPropertyPointers( _splatCloud );
209 swapPredefinedCloudPropertyPointers( _splatCloud );
210 }
211
212
213 //----------------------------------------------------------------
214
215
216 void SplatCloud::clearSplats()
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
231 void SplatCloud::pushbackSplat()
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
246 void 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 }
SplatCloud::swapPredefinedCloudPropertyPointers
void swapPredefinedCloudPropertyPointers(SplatCloud &_splatCloud)
Swap pointers to predefined cloud-properties.
Definition: SplatCloud.hh:696
SplatCloud::getPredefinedCloudPropertyPointers
void getPredefinedCloudPropertyPointers()
Get pointers to predefined cloud-properties.
Definition: SplatCloud.hh:681
SplatCloud::CloudPropertyMapEntry
Definition: SplatCloud.hh:257
SplatCloud::SplatPropertyInterface
Definition: SplatCloud.hh:208
SplatCloud::copyCloudProperties
void copyCloudProperties(const SplatCloud &_splatCloud)
Deep copy all cloud-properties.
Definition: SplatCloud.cc:104
SplatCloud::SplatCloud
SplatCloud()
Standard constructor.
Definition: SplatCloud.hh:87
SplatCloud::CloudPropertyInterface::clone
virtual CloudPropertyInterface * clone() const =0
Return a deep copy of this.
SplatCloud::PropertyHandleT
Definition: SplatCloud.hh:283
SplatCloud::swap
void swap(SplatCloud &_splatCloud)
Swap the content.
Definition: SplatCloud.cc:198
SplatCloud::clearSplatProperties
void clearSplatProperties()
Clear all splat-properties.
Definition: SplatCloud.cc:148
SplatCloud::SplatPropertyInterface::clone
virtual SplatPropertyInterface * clone() const =0
Return a deep copy of this.
SplatCloud.hh
SplatCloud::copySplatProperties
void copySplatProperties(const SplatCloud &_splatCloud)
Deep copy all splat-properties.
Definition: SplatCloud.cc:74
SplatCloud::cloudProperties_
CloudPropertyMap cloudProperties_
Cloud-property map.
Definition: SplatCloud.hh:479
SplatCloud::SplatPropertyMapEntry
Definition: SplatCloud.hh:244
SplatCloud
Definition: SplatCloud.hh:79
SplatCloud::resetPredefinedSplatPropertyPointers
void resetPredefinedSplatPropertyPointers()
Reset pointers to predefined splat-properties.
Definition: SplatCloud.hh:654
SplatCloud::clearCloudProperties
void clearCloudProperties()
Clear all cloud-properties.
Definition: SplatCloud.cc:166
SplatCloud::clear
void clear()
Remove all properties and reset the number of splats.
Definition: SplatCloud.cc:184
SplatCloud::numSplats_
unsigned int numSplats_
Number of splats.
Definition: SplatCloud.hh:186
SplatCloud::pushbackSplat
void pushbackSplat()
Add one element at the end of the data vector of all splat-properties.
Definition: SplatCloud.cc:231
SplatCloud::resizeSplats
void resizeSplats(unsigned int _num)
Resize the data vector of all splat-properties.
Definition: SplatCloud.cc:246
SplatCloud::getPredefinedSplatPropertyPointers
void getPredefinedSplatPropertyPointers()
Get pointers to predefined splat-properties.
Definition: SplatCloud.hh:669
SplatCloud::clearSplats
void clearSplats()
Clear the data vector of all splat-properties.
Definition: SplatCloud.cc:216
SplatCloud::swapPredefinedSplatPropertyPointers
void swapPredefinedSplatPropertyPointers(SplatCloud &_splatCloud)
Swap pointers to predefined splat-properties.
Definition: SplatCloud.hh:684
SplatCloud::SplatPropertyMap
std::map< BasePropertyHandle, SplatPropertyMapEntry > SplatPropertyMap
Definition: SplatCloud.hh:270
SplatCloud::CloudPropertyInterface
Definition: SplatCloud.hh:228
SplatCloud::resetPredefinedCloudPropertyPointers
void resetPredefinedCloudPropertyPointers()
Reset pointers to predefined cloud-properties.
Definition: SplatCloud.hh:666
SplatCloud::CloudPropertyMap
std::map< BasePropertyHandle, CloudPropertyMapEntry > CloudPropertyMap
Definition: SplatCloud.hh:275
SplatCloud::splatProperties_
SplatPropertyMap splatProperties_
Splat-property map.
Definition: SplatCloud.hh:476