File: gdcmSurface.cxx

package info (click to toggle)
gdcm 2.4.4-3%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 32,912 kB
  • ctags: 52,166
  • sloc: cpp: 188,527; ansic: 124,526; xml: 41,799; sh: 7,162; python: 3,667; cs: 2,128; java: 1,344; lex: 1,290; tcl: 677; php: 128; makefile: 116
file content (533 lines) | stat: -rw-r--r-- 11,694 bytes parent folder | download | duplicates (3)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
/*=========================================================================

  Program: GDCM (Grassroots DICOM). A DICOM library

  Copyright (c) 2006-2011 Mathieu Malaterre
  All rights reserved.
  See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "gdcmSurface.h"
#include "gdcmCodeString.h"
#include "gdcmString.h"

#include <cstring>


namespace gdcm
{
static const char * STATESStrings[] = {
  "NO",
  "YES",
  "UNKNOWN",

  0
};

const char * Surface::GetSTATESString(STATES state)
{
  assert( state <= STATES_END );
  return STATESStrings[(int)state];
}

Surface::STATES Surface::GetSTATES(const char * state)
{
  if(!state) return STATES_END;

  // Delete possible space as last character
  String<>  str( state );
  str.Trim();
  const char * stateClear = str.Trim().c_str();

  for(unsigned int i = 0; STATESStrings[i] != 0; ++i)
  {
    if( strcmp(stateClear, STATESStrings[i]) == 0 )
    {
      return (STATES)i;
    }
  }
  // Ouch ! We did not find anything, that's pretty bad, let's hope that
  // the toolkit which wrote the image is buggy and tolerate space padded binary
  // string
  CodeString  codestring  = stateClear;
  std::string cs          = codestring.GetAsString();
  for(unsigned int i = 0; STATESStrings[i] != 0; ++i)
  {
    if( strcmp(cs.c_str(), STATESStrings[i]) == 0 )
    {
      return (STATES)i;
    }
  }

  return STATES_END;
}

static const char * VIEWStrings[] = {
  "SURFACE",
  "WIREFRAME",
  "POINTS",

  0
};

const char * Surface::GetVIEWTypeString(VIEWType type)
{
  assert( type <= VIEWType_END );
  return VIEWStrings[(int)type];
}

Surface::VIEWType Surface::GetVIEWType(const char * type)
{
  if(!type) return VIEWType_END;

  // Delete possible space as last character
  String<>  str( type );
  str.Trim();
  const char * typeClear = str.Trim().c_str();

  for(unsigned int i = 0; VIEWStrings[i] != 0; ++i)
  {
    if( strcmp(typeClear, VIEWStrings[i]) == 0 )
    {
      return (VIEWType)i;
    }
  }
  // Ouch ! We did not find anything, that's pretty bad, let's hope that
  // the toolkit which wrote the image is buggy and tolerate space padded binary
  // string
  CodeString  codestring  = typeClear;
  std::string cs          = codestring.GetAsString();
  for(unsigned int i = 0; VIEWStrings[i] != 0; ++i)
  {
    if( strcmp(cs.c_str(), VIEWStrings[i]) == 0 )
    {
      return (VIEWType)i;
    }
  }

  return VIEWType_END;
}

Surface::Surface():
  SurfaceNumber(0),
  SurfaceComments(""),
  SurfaceProcessing(false),
  SurfaceProcessingRatio(1.),
  SurfaceProcessingDescription(""),
  ProcessingAlgorithm(),
  RecommendedDisplayGrayscaleValue(0),
  RecommendedPresentationOpacity(1),
  RecommendedPresentationType(SURFACE),
  FiniteVolume(UNKNOWN),
  Manifold(UNKNOWN),
  AlgorithmFamily(),
  AlgorithmVersion(""),
  AlgorithmName(""),
  NumberOfSurfacePoints(0),
  PointCoordinatesData(),
  PointPositionAccuracy(0),
  MeanPointDistance(0),
  MaximumPointDistance(0),
  PointsBoundingBoxCoordinates(0),
  AxisOfRotation(0),
  CenterOfRotation(0),
  NumberOfVectors(0),
  VectorDimensionality(0),
  VectorAccuracy(0),
  VectorCoordinateData(),
  Primitive(new MeshPrimitive)
{
  RecommendedDisplayCIELabValue[0] = 0;
  RecommendedDisplayCIELabValue[1] = 0;
  RecommendedDisplayCIELabValue[2] = 0;
}

Surface::~Surface()
{
  if (PointPositionAccuracy != 0)         delete PointPositionAccuracy;
  if (PointsBoundingBoxCoordinates != 0)  delete PointsBoundingBoxCoordinates;
  if (AxisOfRotation != 0)                delete AxisOfRotation;
  if (CenterOfRotation != 0)              delete CenterOfRotation;

  if (VectorAccuracy != 0)                delete VectorAccuracy;
}

unsigned short Surface::GetRecommendedDisplayGrayscaleValue() const
{
  return RecommendedDisplayGrayscaleValue;
}

void Surface::SetRecommendedDisplayGrayscaleValue(const unsigned short vl)
{
  RecommendedDisplayGrayscaleValue = vl;
}

const unsigned short * Surface::GetRecommendedDisplayCIELabValue() const
{
  return &RecommendedDisplayCIELabValue[0];
}

unsigned short Surface::GetRecommendedDisplayCIELabValue(const unsigned int idx) const
{
  assert( idx < 3 );
  return RecommendedDisplayCIELabValue[idx];
}

void Surface::SetRecommendedDisplayCIELabValue(const unsigned short vl[3])
{
  RecommendedDisplayCIELabValue[0] = vl[0];
  RecommendedDisplayCIELabValue[1] = vl[1];
  RecommendedDisplayCIELabValue[2] = vl[2];
}

void Surface::SetRecommendedDisplayCIELabValue(const unsigned short vl, const unsigned int idx/* = 0*/)
{
  assert( idx < 3 );
  RecommendedDisplayCIELabValue[idx] = vl;
}

void Surface::SetRecommendedDisplayCIELabValue(const std::vector< unsigned short > & vl)
{
  assert( vl.size() > 2 );

  RecommendedDisplayCIELabValue[0] = vl[0];
  RecommendedDisplayCIELabValue[1] = vl[1];
  RecommendedDisplayCIELabValue[2] = vl[2];
}

float Surface::GetRecommendedPresentationOpacity() const
{
  return RecommendedPresentationOpacity;
}

void Surface::SetRecommendedPresentationOpacity(float opacity)
{
  if( (0 <= opacity) && (opacity <= 1) )
  {
    RecommendedPresentationOpacity = opacity;
  }
  //else keep default value : 1
}

Surface::VIEWType Surface::GetRecommendedPresentationType() const
{
  return RecommendedPresentationType;
}

void Surface::SetRecommendedPresentationType(VIEWType type)
{
  if( type < VIEWType_END)
  {
    RecommendedPresentationType = type;
  }
}

unsigned long Surface::GetSurfaceNumber() const
{
  return SurfaceNumber;
}

void Surface::SetSurfaceNumber(const unsigned long nb)
{
  SurfaceNumber = nb;
}

const char * Surface::GetSurfaceComments() const
{
  return SurfaceComments.c_str();
}

void Surface::SetSurfaceComments(const char * comment)
{
  SurfaceComments = comment;
}

bool Surface::GetSurfaceProcessing() const
{
  return SurfaceProcessing;
}

void Surface::SetSurfaceProcessing(bool b)
{
  SurfaceProcessing = b;
}

float Surface::GetSurfaceProcessingRatio() const
{
  return SurfaceProcessingRatio;
}

void Surface::SetSurfaceProcessingRatio(const float ratio)
{
  SurfaceProcessingRatio = ratio;
}

const char * Surface::GetSurfaceProcessingDescription() const
{
  return SurfaceProcessingDescription.c_str();
}

void Surface::SetSurfaceProcessingDescription(const char * description)
{
  SurfaceProcessingDescription = description;
}

SegmentHelper::BasicCodedEntry const & Surface::GetProcessingAlgorithm() const
{
  return ProcessingAlgorithm;
}

SegmentHelper::BasicCodedEntry & Surface::GetProcessingAlgorithm()
{
  return ProcessingAlgorithm;
}

void Surface::SetProcessingAlgorithm(SegmentHelper::BasicCodedEntry const & BSE)
{
  ProcessingAlgorithm.CV   = BSE.CV;
  ProcessingAlgorithm.CSD  = BSE.CSD;
  ProcessingAlgorithm.CM   = BSE.CM;
}

Surface::STATES Surface::GetFiniteVolume() const
{
  return FiniteVolume;
}

void Surface::SetFiniteVolume(STATES state)
{
  assert( state < STATES_END );
  FiniteVolume = state;
}

Surface::STATES Surface::GetManifold() const
{
  return Manifold;
}

void Surface::SetManifold(STATES state)
{
  assert( state < STATES_END );
  Manifold = state;
}

SegmentHelper::BasicCodedEntry const & Surface::GetAlgorithmFamily() const
{
  return AlgorithmFamily;
}

SegmentHelper::BasicCodedEntry & Surface::GetAlgorithmFamily()
{
  return AlgorithmFamily;
}

void Surface::SetAlgorithmFamily(SegmentHelper::BasicCodedEntry const & BSE)
{
  AlgorithmFamily.CV   = BSE.CV;
  AlgorithmFamily.CSD  = BSE.CSD;
  AlgorithmFamily.CM   = BSE.CM;
}

const char * Surface::GetAlgorithmVersion() const
{
  return AlgorithmVersion.c_str();
}

void Surface::SetAlgorithmVersion(const char * str)
{
  AlgorithmVersion = str;
}

const char * Surface::GetAlgorithmName() const
{
  return AlgorithmName.c_str();
}

void Surface::SetAlgorithmName(const char * str)
{
  AlgorithmName = str;
}

unsigned long Surface::GetNumberOfSurfacePoints() const
{
  return NumberOfSurfacePoints;
}

void Surface::SetNumberOfSurfacePoints(const unsigned long nb)
{
  NumberOfSurfacePoints = nb;
}

const DataElement & Surface::GetPointCoordinatesData() const
{
  return PointCoordinatesData;
}

DataElement & Surface::GetPointCoordinatesData()
{
  return PointCoordinatesData;
}

void Surface::SetPointCoordinatesData(DataElement const & de)
{
  PointCoordinatesData = de;
}


const float * Surface::GetPointPositionAccuracy() const
{
  return PointPositionAccuracy;
}

void Surface::SetPointPositionAccuracy(const float * accuracies)
{
  assert(accuracies);

  if (PointPositionAccuracy == 0) PointPositionAccuracy = new float[3];

  PointPositionAccuracy[0] = accuracies[0];
  PointPositionAccuracy[1] = accuracies[1];
  PointPositionAccuracy[2] = accuracies[2];
}

float Surface::GetMeanPointDistance() const
{
  return MeanPointDistance;
}

void Surface::SetMeanPointDistance(float average)
{
  MeanPointDistance = average;
}

float Surface::GetMaximumPointDistance() const
{
  return MaximumPointDistance;
}

void Surface::SetMaximumPointDistance(float maximum)
{
  MaximumPointDistance = maximum;
}

const float * Surface::GetPointsBoundingBoxCoordinates() const
{
  return PointsBoundingBoxCoordinates;
}

void Surface::SetPointsBoundingBoxCoordinates(const float * coordinates)
{
  assert(coordinates);

  if (PointsBoundingBoxCoordinates == 0) PointsBoundingBoxCoordinates = new float[6];

  PointsBoundingBoxCoordinates[0] = coordinates[0];
  PointsBoundingBoxCoordinates[1] = coordinates[1];
  PointsBoundingBoxCoordinates[2] = coordinates[2];
  PointsBoundingBoxCoordinates[3] = coordinates[3];
  PointsBoundingBoxCoordinates[4] = coordinates[4];
  PointsBoundingBoxCoordinates[5] = coordinates[5];
}

const float * Surface::GetAxisOfRotation() const
{
  return AxisOfRotation;
}

void Surface::SetAxisOfRotation(const float * axis)
{
  assert(axis);

  if (AxisOfRotation == 0) AxisOfRotation = new float[3];

  AxisOfRotation[0] = axis[0];
  AxisOfRotation[1] = axis[1];
  AxisOfRotation[2] = axis[2];
}

const float * Surface::GetCenterOfRotation() const
{
  return CenterOfRotation;
}

void Surface::SetCenterOfRotation(const float * center)
{
  assert(center);

  if (CenterOfRotation == 0) CenterOfRotation = new float[3];

  CenterOfRotation[0] = center[0];
  CenterOfRotation[1] = center[1];
  CenterOfRotation[2] = center[2];
}

unsigned long Surface::GetNumberOfVectors() const
{
  return NumberOfVectors;
}

void Surface::SetNumberOfVectors(const unsigned long nb)
{
  NumberOfVectors = nb;
}

unsigned short Surface::GetVectorDimensionality() const
{
  return VectorDimensionality;
}

void Surface::SetVectorDimensionality(const unsigned short dim)
{
  VectorDimensionality = dim;
}

const float * Surface::GetVectorAccuracy() const
{
  return VectorAccuracy;
}

void Surface::SetVectorAccuracy(const float * accuracy)
{
  assert(accuracy);

  if (VectorAccuracy == 0) VectorAccuracy = new float[ VectorDimensionality ];

  for (unsigned int i = 0; i < VectorDimensionality; ++i)
    VectorAccuracy[i] = accuracy[i];
}

const DataElement & Surface::GetVectorCoordinateData() const
{
  return VectorCoordinateData;
}

DataElement & Surface::GetVectorCoordinateData()
{
  return VectorCoordinateData;
}

void Surface::SetVectorCoordinateData(DataElement const & de)
{
  VectorCoordinateData = de;
}

MeshPrimitive const & Surface::GetMeshPrimitive() const
{
  return *Primitive;
}

MeshPrimitive & Surface::GetMeshPrimitive()
{
  return *Primitive;
}

void Surface::SetMeshPrimitive(MeshPrimitive & mp)
{
  Primitive = mp;
}

}