SplatCloud.cc 9.66 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
\*===========================================================================*/

/*===========================================================================*\
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
\*===========================================================================*/

43
44
45
46
47
48
49
50
51
52
53
54
//================================================================
//
//  CLASS SplatCloud - IMPLEMENTATION
//
//================================================================


//== INCLUDES ====================================================


#include "SplatCloud.hh"

55
#include <iostream>
56
57


58
//== STATIC MEMBERS ==============================================
59

60

61
62
63
64
65
66
67
68
69
70
71
const SplatCloud::PositionsHandle  SplatCloud::POSITIONS_HANDLE ( "<Positions>"  );
const SplatCloud::ColorsHandle     SplatCloud::COLORS_HANDLE    ( "<Colors>"     );
const SplatCloud::NormalsHandle    SplatCloud::NORMALS_HANDLE   ( "<Normals>"    );
const SplatCloud::PointsizesHandle SplatCloud::POINTSIZES_HANDLE( "<Pointsizes>" );
const SplatCloud::IndicesHandle    SplatCloud::INDICES_HANDLE   ( "<Indices>"    );
const SplatCloud::ViewlistsHandle  SplatCloud::VIEWLISTS_HANDLE ( "<Viewlists>"  );
const SplatCloud::SelectionsHandle SplatCloud::SELECTIONS_HANDLE( "<Selections>" );


//== IMPLEMENTATION ==============================================

72

73
74
75
void SplatCloud::copySplatProperties( const SplatCloud &_splatCloud )
{
  // deep copy all splat-properties
76
  SplatPropertyMap::const_iterator splatPropertyIter;
77
78
79
  for( splatPropertyIter = _splatCloud.splatProperties_.begin(); splatPropertyIter != _splatCloud.splatProperties_.end(); ++splatPropertyIter )
  {
    // create new deep copy of current splat-property
80
    SplatPropertyInterface *prop = splatPropertyIter->second.property_->clone();
81
82
83
84

    // check if out of memory
    if( prop == 0 )
    {
85
      std::cerr << "Out of memory for a copy of SplatCloud's splat-property \"" << splatPropertyIter->first << "\"." << std::endl;
86
87
88
      continue;
    }

89
90
    // insert new property map entry into splat-property map with same name as before
    splatProperties_[ splatPropertyIter->first ] = SplatPropertyMapEntry( prop, splatPropertyIter->second.numRequests_ );
91
92
93
94
95
96
  }

  // Get pointers to predefined splat-properties.
  // These can *not* be copied because they have to point to the newly
  // created deep copies of the properties and not to the old properties.
  getPredefinedSplatPropertyPointers();
97
98
99
100
101
102
}


//----------------------------------------------------------------


103
void SplatCloud::copyCloudProperties( const SplatCloud &_splatCloud )
104
{
105
  // deep copy all cloud-properties
106
  CloudPropertyMap::const_iterator cloudPropertyIter;
107
108
109
  for( cloudPropertyIter = _splatCloud.cloudProperties_.begin(); cloudPropertyIter != _splatCloud.cloudProperties_.end(); ++cloudPropertyIter )
  {
    // create new deep copy of current cloud-property
110
    CloudPropertyInterface *prop = cloudPropertyIter->second.property_->clone();
111
112
113
114

    // check if out of memory
    if( prop == 0 )
    {
115
      std::cerr << "Out of memory for a copy of SplatCloud's cloud-property \"" << cloudPropertyIter->first << "\"." << std::endl;
116
117
118
      continue;
    }

119
120
    // insert new property map entry into cloud-property map with same name as before
    cloudProperties_[ cloudPropertyIter->first ] = CloudPropertyMapEntry( prop, cloudPropertyIter->second.numRequests_ );
121
122
123
124
125
126
  }

  // Get pointers to predefined cloud-properties.
  // These can *not* be copied because they have to point to the newly
  // created deep copies of the properties and not to the old properties.
  getPredefinedCloudPropertyPointers();
127
128
129
130
131
132
}


//----------------------------------------------------------------


133
SplatCloud::SplatCloud( const SplatCloud &_splatCloud )
134
{
135
136
137
138
139
140
  // copy number of splats
  numSplats_ = _splatCloud.numSplats_;

  // deep copy all properties
  copySplatProperties( _splatCloud );
  copyCloudProperties( _splatCloud );
141
142
143
144
145
146
}


//----------------------------------------------------------------


147
void SplatCloud::clearSplatProperties()
148
{
149
  // free memory of all splat-properties
150
  SplatPropertyMap::const_iterator splatPropertyIter;
151
  for( splatPropertyIter = splatProperties_.begin(); splatPropertyIter != splatProperties_.end(); ++splatPropertyIter )
152
    delete splatPropertyIter->second.property_;
153
154

  // clear splat-property map
155
  SplatPropertyMap().swap( splatProperties_ );
156
157
158

  // reset pointers to predefined splat-properties
  resetPredefinedSplatPropertyPointers();
159
160
161
162
163
164
}


//----------------------------------------------------------------


165
void SplatCloud::clearCloudProperties()
166
{
167
  // free memory of all cloud-properties
168
  CloudPropertyMap::const_iterator cloudPropertyIter;
169
  for( cloudPropertyIter = cloudProperties_.begin(); cloudPropertyIter != cloudProperties_.end(); ++cloudPropertyIter )
170
    delete cloudPropertyIter->second.property_;
171
172

  // clear cloud-property map
173
  CloudPropertyMap().swap( cloudProperties_ );
174
175
176

  // reset pointers to predefined cloud-properties
  resetPredefinedCloudPropertyPointers();
177
178
179
180
181
182
}


//----------------------------------------------------------------


183
void SplatCloud::clear()
184
{
185
186
187
188
189
190
191
192
  // reset number of splats
  numSplats_ = 0;

  // clear all properties
  clearSplatProperties();
  clearCloudProperties();
}

193

194
//----------------------------------------------------------------
195
196


197
198
199
200
void SplatCloud::swap( SplatCloud &_splatCloud )
{
  // swap number of splats
  std::swap( numSplats_,       _splatCloud.numSplats_       );
201

202
203
204
  // swap all properties
  std::swap( splatProperties_, _splatCloud.splatProperties_ );
  std::swap( cloudProperties_, _splatCloud.cloudProperties_ );
205

206
207
208
  // swap pointers to predefined properties
  swapPredefinedSplatPropertyPointers( _splatCloud );
  swapPredefinedCloudPropertyPointers( _splatCloud );
209
210
211
212
213
214
}


//----------------------------------------------------------------


215
void SplatCloud::clearSplats()
216
{
217
  // clear data vector of all splat-properties
218
  SplatPropertyMap::const_iterator splatPropertyIter;
219
  for( splatPropertyIter = splatProperties_.begin(); splatPropertyIter != splatProperties_.end(); ++splatPropertyIter )
220
    splatPropertyIter->second.property_->clear();
221
222
223

  // reset number of splats
  numSplats_ = 0;
224
225
226
227
228
229
}


//----------------------------------------------------------------


230
void SplatCloud::pushbackSplat()
231
{
232
  // add one element at end of data vector of all splat-properties
233
  SplatPropertyMap::const_iterator splatPropertyIter;
234
  for( splatPropertyIter = splatProperties_.begin(); splatPropertyIter != splatProperties_.end(); ++splatPropertyIter )
235
    splatPropertyIter->second.property_->pushback();
236
237
238

  // increase number of splats
  ++numSplats_;
239
240
241
242
243
244
}


//----------------------------------------------------------------


245
void SplatCloud::resizeSplats( unsigned int _num )
246
{
247
  // resize data vector of all splat-properties
248
  SplatPropertyMap::const_iterator splatPropertyIter;
249
  for( splatPropertyIter = splatProperties_.begin(); splatPropertyIter != splatProperties_.end(); ++splatPropertyIter )
250
    splatPropertyIter->second.property_->resize( _num );
251
252
253

  // update number of splats
  numSplats_ = _num;
254
}