Shapeworks Studio  2.1
Shape analysis software suite
itkPSMShapeMatrixAttribute.hxx
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkPSMShapeMatrixAttribute_hxx
19 #define __itkPSMShapeMatrixAttribute_hxx
20 #include "itkPSMShapeMatrixAttribute.h"
21 
22 namespace itk
23 {
24 
25 template <class T, unsigned int VDimension>
27 {
28  const ParticleDomainAddEvent &event = dynamic_cast<const ParticleDomainAddEvent &>(e);
29  unsigned int d = event.GetDomainIndex();
30 
31  if ( d % m_DomainsPerShape == 0 )
32  {
33  this->ResizeMatrix(this->rows(), this->cols()+1);
34  }
35 }
36 
37 template <class T, unsigned int VDimension>
39 {
40  vnl_matrix<T> tmp(*this); // copy existing matrix
41 
42  // Create new column (shape)
43  this->set_size(rs, cs);
44 
45  // Copy old data into new matrix.
46  for (unsigned int c = 0; c < tmp.cols(); c++)
47  {
48  for (unsigned int r = 0; r < tmp.rows(); r++)
49  {
50  this->operator()(r,c) = tmp(r,c);
51  }
52  }
53 }
54 
55 template <class T, unsigned int VDimension>
57 {
58  const ParticlePositionAddEvent &event = dynamic_cast<const ParticlePositionAddEvent &>(e);
59  const PSMParticleSystem<VDimension> *ps= dynamic_cast<const PSMParticleSystem<VDimension> *>(o);
60  const int d = event.GetDomainIndex();
61  const unsigned int idx = event.GetPositionIndex();
62  const typename PSMParticleSystem<VDimension>::PointType pos = ps->GetTransformedPosition(idx, d);
63 
64  const unsigned int PointsPerDomain = ps ->GetNumberOfParticles(d);
65 
66  // Make sure we have enough rows.
67  if ((ps->GetNumberOfParticles(d) * VDimension * m_DomainsPerShape) > this->rows())
68  {
69  this->ResizeMatrix(PointsPerDomain * VDimension * m_DomainsPerShape, this->cols());
70  }
71 
72  // CANNOT ADD POSITION INFO UNTIL ALL POINTS PER DOMAIN IS KNOWN
73  // Add position info to the matrix
74  unsigned int k = ((d % m_DomainsPerShape) * PointsPerDomain * VDimension)
75  + (idx * VDimension);
76  for (unsigned int i = 0; i < VDimension; i++)
77  {
78  this->operator()(i+k, d / m_DomainsPerShape) = pos[i];
79  }
80 }
81 
82 template <class T, unsigned int VDimension>
84 {
85  const ParticlePositionSetEvent &event = dynamic_cast<const ParticlePositionSetEvent &>(e);
86  const PSMParticleSystem<VDimension> *ps= dynamic_cast<const PSMParticleSystem<VDimension> *>(o);
87  const int d = event.GetDomainIndex();
88  const unsigned int idx = event.GetPositionIndex();
89  const typename PSMParticleSystem<VDimension>::PointType pos = ps->GetTransformedPosition(idx, d);
90  const unsigned int PointsPerDomain = ps ->GetNumberOfParticles(d);
91 
92  // Modify matrix info
93  // unsigned int k = VDimension * idx;
94  unsigned int k = ((d % m_DomainsPerShape) * PointsPerDomain * VDimension)
95  + (idx * VDimension);
96  for (unsigned int i = 0; i < VDimension; i++)
97  {
98  this->operator()(i+k, d / m_DomainsPerShape) = pos[i];
99  }
100 }
101 
102 } // end namespace itk
103 
104 
105 #endif
virtual void PositionSetEventCallback(Object *o, const EventObject &e)
unsigned long int GetNumberOfParticles(unsigned int d=0) const
A facade class that manages interactions with a particle system.
virtual void DomainAddEventCallback(Object *, const EventObject &e)
virtual void PositionAddEventCallback(Object *o, const EventObject &e)
Definition: Shape.h:14