Statismo  0.10.1
 All Classes Namespaces Functions Typedefs
vtkUnstructuredGridRepresenter.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 vtkUnstructuredGridREPRESENTER_H_
40 #define vtkUnstructuredGridREPRESENTER_H_
41 
42 #include <H5Cpp.h>
43 
44 #include <vtkLandmarkTransform.h>
45 #include <vtkSmartPointer.h>
46 #include <vtkTransform.h>
47 #include <vtkTransformPolyDataFilter.h>
48 #include <vtkUnstructuredGrid.h>
49 
50 #include "CommonTypes.h"
51 #include "Domain.h"
52 #include "vtkHelper.h"
53 
69  public:
70 
72  typedef vtkUnstructuredGrid* DatasetPointerType;
73  typedef const vtkUnstructuredGrid* DatasetConstPointerType;
74 
77 
79 
80  struct DatasetInfo {}; // not used for this representer, but needs to be here as it is part of the generic interface
81 
82 
83 
84  enum AlignmentType {
85  NONE=999, // something that VTK does not define
86  RIGID=VTK_LANDMARK_RIGIDBODY,
87  SIMILARITY=VTK_LANDMARK_SIMILARITY,
88  AFFINE=VTK_LANDMARK_AFFINE
89  };
90 
91  static vtkUnstructuredGridRepresenter* Create(DatasetConstPointerType reference, AlignmentType alignment) {
92  return new vtkUnstructuredGridRepresenter(reference, alignment);
93  }
94 
95  static vtkUnstructuredGridRepresenter* Load(const H5::CommonFG& fg);
96 
97  vtkUnstructuredGridRepresenter* Clone() const;
98  void Delete() const {
99  delete this;
100  }
101 
103 
104 
105  static std::string GetName() {
106  return "vtkUnstructuredGridRepresenter";
107  }
108  static unsigned GetDimensions() {
109  return 3;
110  }
111 
112  const DomainType& GetDomain() const {
113  return m_domain;
114  }
115 
116  AlignmentType GetAlignment() const {
117  return m_alignment;
118  }
119 
120  DatasetConstPointerType GetReference() const {
121  return m_reference;
122  }
123 
124  statismo::VectorType PointToVector(const PointType& pt) const;
125  DatasetPointerType DatasetToSample(DatasetConstPointerType ds, DatasetInfo* notUsed) const;
126  statismo::VectorType SampleToSampleVector(DatasetConstPointerType sample) const;
127  DatasetPointerType SampleVectorToSample(const statismo::VectorType& sample) const;
128 
129  ValueType PointSampleFromSample(DatasetConstPointerType sample, unsigned ptid) const;
130  statismo::VectorType PointSampleToPointSampleVector(const ValueType& v) const;
131  ValueType PointSampleVectorToPointSample(const statismo::VectorType& pointSample) const;
132 
133 
134  void Save(const H5::CommonFG& fg) const;
135  unsigned GetNumberOfPoints() const;
136  unsigned GetPointIdForPoint(const PointType& point) const;
137 
138 
139  static void DeleteDataset(DatasetPointerType d) ;
140 
141  /* Maps a (Pointid,component) tuple to a component of the internal matrix.
142  * This is used to locate the place in the matrix to store the elements for a given point.
143  * @params ptId The point id
144  * @params the Component Index (range 0, Dimensionality)
145  * @returns an index.
146  */
147  static unsigned MapPointIdToInternalIdx(unsigned ptId, unsigned componentInd) {
148  return ptId * GetDimensions() + componentInd;
149  }
150 
151 
152 
153  private:
154 
155  vtkUnstructuredGridRepresenter(const std::string& reference, AlignmentType alignment);
156  vtkUnstructuredGridRepresenter(const DatasetConstPointerType reference, AlignmentType alignment);
159 
160  static DatasetPointerType ReadDataset(const std::string& filename);
161  static void WriteDataset(const std::string& filename, DatasetConstPointerType pd) ;
162 
163 
164  DatasetPointerType m_reference;
165 
166  vtkTransformPolyDataFilter* m_pdTransform;
167  AlignmentType m_alignment;
168  DomainType m_domain;
169 };
170 
171 #endif /* vtkUnstructuredGridREPRESENTER_H_ */
vtkUnstructuredGrid * DatasetPointerType
The type of the data set to be used.
Definition: vtkUnstructuredGridRepresenter.h:72
A representer for vtkUnstructuredGrid using Procrustes alignment to align the datasets.
Definition: vtkUnstructuredGridRepresenter.h:68
Helper class that represents a vtkPoint. In vtk a point is just of type T*. The statismo library reli...
Definition: vtkHelper.h:119
Definition: Domain.h:51