Statismo  0.10.1
 All Classes Namespaces Functions Typedefs
vtkStandardImageRepresenter.h
1 /*
2  * This file is part of the statismo library.
3  *
4  * Author: Marcel Luethi (marcel.luethi@unibas.ch)
5  *
6  * Copyright (c) 2011 University of Basel
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  *
16  * Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in the
18  * documentation and/or other materials provided with the distribution.
19  *
20  * Neither the name of the project's author nor the names of its
21  * contributors may be used to endorse or promote products derived from
22  * this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
30  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37 
38 #ifndef VTKSTANDARDIMAGERESENTER_H_
39 #define VTKSTANDARDIMAGERESENTER_H_
40 
41 #include <H5Cpp.h>
42 
43 #include <vtkSmartPointer.h>
44 #include <vtkStructuredPoints.h>
45 
46 #include "CommonTypes.h"
47 #include "Domain.h"
48 #include "Representer.h"
49 #include "vtkHelper.h"
50 
51 
64 namespace statismo {
65 template <>
66 struct RepresenterTraits<vtkStructuredPoints> {
67  typedef vtkStructuredPoints* DatasetPointerType;
68  typedef const vtkStructuredPoints* DatasetConstPointerType;
69 
70  typedef vtkPoint PointType;
71  typedef vtkNDPixel ValueType;
73 
74 
75 };
76 
77 
78 
79 template <class TScalar, unsigned PixelDimensions>
80 class vtkStandardImageRepresenter : public Representer<vtkStructuredPoints> {
81  public:
82 
83 
84 
85  static vtkStandardImageRepresenter* Create(const vtkStructuredPoints* reference) {
86  return new vtkStandardImageRepresenter(reference);
87  }
88  static vtkStandardImageRepresenter* Create() {
89  return new vtkStandardImageRepresenter();
90  }
91 
92  void Load(const H5::Group& fg);
93  vtkStandardImageRepresenter* Clone() const;
94 
95  virtual ~vtkStandardImageRepresenter();
96  void Delete() const {
97  delete this;
98  }
99 
100  void DeleteDataset(DatasetPointerType d) const {
101  d->Delete();
102  };
103 
104  DatasetPointerType CloneDataset(DatasetConstPointerType d) const {
105  vtkStructuredPoints* clone = vtkStructuredPoints::New();
106  clone->DeepCopy(const_cast<vtkStructuredPoints*>(d));
107  return clone;
108  }
109 
110 
111  unsigned GetDimensions() const {
112  return PixelDimensions;
113  }
114  std::string GetVersion() const {
115  return "1.0" ;
116  }
117  RepresenterDataType GetType() const {
118  return IMAGE;
119  }
120  const DomainType& GetDomain() const {
121  return m_domain;
122  }
123 
124  std::string GetName() const {
125  return "vtkStandardImageRepresenter";
126  }
127 
128  const vtkStructuredPoints* GetReference() const {
129  return m_reference;
130  }
131 
132  statismo::VectorType PointToVector(const PointType& pt) const;
133  DatasetPointerType DatasetToSample(DatasetConstPointerType ds) const;
134  statismo::VectorType SampleToSampleVector(DatasetConstPointerType sample) const;
135  DatasetPointerType SampleVectorToSample(const statismo::VectorType& sample) const;
136 
137 
138  ValueType PointSampleFromSample(DatasetConstPointerType sample, unsigned ptid) const;
139  statismo::VectorType PointSampleToPointSampleVector(const ValueType& v) const;
140  ValueType PointSampleVectorToPointSample(const statismo::VectorType& samplePoint) const;
141 
142  unsigned GetPointIdForPoint(const PointType& pt) const;
143 
144  unsigned GetNumberOfPoints() const;
145  void Save(const H5::Group& fg) const;
146 
147  static unsigned GetNumberOfPoints(DatasetPointerType reference);
148 
149 
150  private:
151 
152  vtkStructuredPoints* LoadRefLegacy(const H5::Group& fg) const;
153  vtkStructuredPoints* LoadRef(const H5::Group& fg) const;
154 
155  vtkStandardImageRepresenter(DatasetConstPointerType reference);
156  vtkStandardImageRepresenter() : m_reference(0) {}
157  void SetReference(DatasetConstPointerType reference);
158 
159  vtkStructuredPoints* m_reference;
160  DomainType m_domain;
161 };
162 
163 } // namespace statismo
164 
165 #include "vtkStandardImageRepresenter.hxx"
166 
167 #endif /* VTKStandardImageRepRESENTER_H_ */
Definition: Domain.h:51