Statismo  0.10.1
 All Classes Namespaces Functions Typedefs
vtkStandardMeshRepresenter.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 
39 #ifndef VTK_STANDARD_MESH_REPRESENTER_H_
40 #define VTK_STANDARD_MESH_REPRESENTER_H_
41 
42 #include <H5Cpp.h>
43 
44 #include <vtkPolyData.h>
45 #include <vtkSmartPointer.h>
46 
47 #include "CommonTypes.h"
48 #include "Domain.h"
49 #include "Representer.h"
50 #include "vtkHelper.h"
51 
52 namespace statismo {
53 
54 
55 template <>
56 struct RepresenterTraits<vtkPolyData> {
57  typedef vtkPolyData* DatasetPointerType;
58  typedef const vtkPolyData* DatasetConstPointerType;
59 
60  typedef vtkPoint PointType;
61  typedef vtkPoint ValueType;
62 
64 
65 
66 };
67 
68 
69 
77 class vtkStandardMeshRepresenter : public Representer<vtkPolyData> {
78  public:
79 
80 
81  static vtkStandardMeshRepresenter* Create() {
82  return new vtkStandardMeshRepresenter();
83  }
84 
85  static vtkStandardMeshRepresenter* Create(const vtkPolyData* reference) {
86  return new vtkStandardMeshRepresenter(reference);
87  }
88 
89 
90  void Load(const H5::Group& fg);
91 
92  vtkStandardMeshRepresenter* Clone() const;
93  void Delete() const {
94  delete this;
95  }
96 
97  virtual ~vtkStandardMeshRepresenter();
98 
99 
100  std::string GetName() const {
101  return "vtkStandardMeshRepresenter";
102  }
103  unsigned GetDimensions() const {
104  return 3;
105  }
106  std::string GetVersion() const {
107  return "1.0" ;
108  }
109  RepresenterDataType GetType() const {
110  return POLYGON_MESH;
111  }
112  const DomainType& GetDomain() const {
113  return m_domain;
114  }
115 
116  void DeleteDataset(DatasetPointerType d) const {
117  d->Delete();
118  };
119 
120  DatasetPointerType CloneDataset(DatasetConstPointerType d) const {
121  vtkPolyData* clone = vtkPolyData::New();
122  clone->DeepCopy(const_cast<vtkPolyData*>(d));
123  return clone;
124  }
125 
126  DatasetConstPointerType GetReference() const {
127  return m_reference;
128  }
129  statismo::VectorType PointToVector(const PointType& pt) const;
130  statismo::VectorType SampleToSampleVector(DatasetConstPointerType sample) const;
131  DatasetPointerType SampleVectorToSample(const statismo::VectorType& sample) const;
132 
133  ValueType PointSampleFromSample(DatasetConstPointerType sample, unsigned ptid) const;
134  statismo::VectorType PointSampleToPointSampleVector(const ValueType& v) const;
135  ValueType PointSampleVectorToPointSample(const statismo::VectorType& pointSample) const;
136 
137 
138  void Save(const H5::Group& fg) const;
139  unsigned GetNumberOfPoints() const;
140  unsigned GetPointIdForPoint(const PointType& point) const;
141 
142 
143  private:
144 
145  vtkStandardMeshRepresenter() : m_reference(0) {}
146  vtkStandardMeshRepresenter(const std::string& reference);
147  vtkStandardMeshRepresenter(const DatasetConstPointerType reference);
150 
151  void SetReference(const vtkPolyData* reference);
152 
153  vtkPolyData* LoadRefLegacy(const H5::Group& fg) const;
154  vtkPolyData* LoadRef(const H5::Group& fg) const;
155 
156  void WriteDataArray(const H5::CommonFG& group, const std::string& name, const vtkDataArray* ds) const;
157  static vtkDataArray* GetAsDataArray(const H5::Group& group, const std::string& name);
158  static void FillDataArray(const statismo::GenericEigenType<double>::MatrixType& m, vtkDataArray* dataArray);
159  DatasetPointerType m_reference;
160 
161  DomainType m_domain;
162 };
163 
164 } // namespace statismo
165 
166 #endif /* VTK_STANDARD_MESH_REPRESENTER_H_ */
A representer for vtkPolyData, which stores the represnter data in the standard mesh format defined f...
Definition: vtkStandardMeshRepresenter.h:77
Definition: Domain.h:51