18 #ifndef __itkPSMParticleSystem_hxx 19 #define __itkPSMParticleSystem_hxx 20 #include "itkPSMParticleSystem.h" 22 #include "itkCommand.h" 27 template <
unsigned int VDimension>
28 PSMParticleSystem<VDimension>::PSMParticleSystem()
32 template <
unsigned int VDimension>
38 if (num == m_Domains.size())
42 m_Domains.resize(num);
43 m_Transforms.resize(num);
44 m_InverseTransforms.resize(num);
45 m_PrefixTransforms.resize(num);
46 m_InversePrefixTransforms.resize(num);
47 m_Positions.resize(num);
48 m_IndexCounters.resize(num);
49 m_Neighborhoods.resize(num);
50 m_DomainFlags.resize(num);
54 template <
unsigned int VDimension>
59 for (
unsigned int idx = 0; idx < m_Domains.size(); ++idx)
63 m_Domains[idx] = input;
64 m_Positions[idx] = PointContainerType::New();
65 m_IndexCounters[idx] = 0;
70 this->SetNumberOfDomains(static_cast<int>(m_Domains.size() + 1));
71 m_Domains[
static_cast<int>( m_Domains.size() ) - 1] = input;
72 m_Positions[
static_cast<int>( m_Domains.size() ) - 1] = PointContainerType::New();
73 m_IndexCounters[
static_cast<int>( m_Domains.size() -1)] = 0;
74 m_Neighborhoods[
static_cast<int>( m_Domains.size() -1)] = NeighborhoodType::New();
75 m_Transforms[
static_cast<int>( m_Domains.size() -1)].set_identity();
76 m_InverseTransforms[
static_cast<int>( m_Domains.size() -1)].set_identity();
77 m_PrefixTransforms[
static_cast<int>( m_Domains.size() -1)].set_identity();
78 m_InversePrefixTransforms[
static_cast<int>( m_Domains.size() -1)].set_identity();
79 m_DomainFlags[
static_cast<int>( m_Domains.size() -1)] =
false;
82 ParticleDomainAddEvent e;
83 e.SetDomainIndex(m_Domains.size() - 1);
84 e.SetPositionIndex(0);
85 e.SetThreadID(threadId);
89 template <
unsigned int VDimension>
93 Superclass::PrintSelf(os, indent);
95 os << indent <<
"m_IndexCounters.size(): " << m_IndexCounters.size() << std::endl;
96 os << indent <<
"m_Positions.size() : " << m_Positions.size() << std::endl;
97 os << indent <<
"m_Domains.size() : " << m_Domains.size() << std::endl;
100 template <
unsigned int VDimension>
105 m_InverseTransforms[i] = this->InvertTransform(T);
108 ParticleTransformSetEvent e;
109 e.SetThreadID(threadId);
111 this->InvokeEvent(e);
114 template <
unsigned int VDimension>
118 m_PrefixTransforms[i] = T;
119 m_InversePrefixTransforms[i] = this->InvertTransform(T);
122 ParticlePrefixTransformSetEvent e;
123 e.SetThreadID(threadId);
125 this->InvokeEvent(e);
128 template <
unsigned int VDimension>
132 m_Neighborhoods[i] = N;
133 m_Neighborhoods[i]->SetDomain(m_Domains[i]);
134 m_Neighborhoods[i]->SetPointContainer(m_Positions[i]);
137 ParticleNeighborhoodSetEvent e;
138 e.SetThreadID(threadId);
140 this->InvokeEvent(e);
143 template <
unsigned int VDimension>
147 m_Positions[d]->operator[](m_IndexCounters[d]) = p;
151 m_Domains[d]->ApplyConstraints( m_Positions[d]->
operator[](m_IndexCounters[d]));
153 m_Neighborhoods[d]->AddPosition( m_Positions[d]->
operator[](m_IndexCounters[d]),
154 m_IndexCounters[d], threadId);
157 if (m_IndexCounters[0] >= m_FixedParticleFlags.size())
159 m_FixedParticleFlags.push_back(
false);
163 ParticlePositionAddEvent e;
164 e.SetThreadID(threadId);
166 e.SetPositionIndex(m_IndexCounters[d]);
167 this->InvokeEvent(e);
168 m_IndexCounters[d]++;
170 return m_Positions[d]->operator[](m_IndexCounters[d]-1);
173 template <
unsigned int VDimension>
176 unsigned int d,
int threadId)
178 if (m_FixedParticleFlags[k] ==
false)
180 m_Positions[d]->operator[](k) = p;
184 m_Domains[d]->ApplyConstraints( m_Positions[d]->
operator[](k));
186 m_Neighborhoods[d]->SetPosition( m_Positions[d]->
operator[](k), k,
191 ParticlePositionSetEvent e;
192 e.SetThreadID(threadId);
194 e.SetPositionIndex(k);
196 this->InvokeEvent(e);
198 return m_Positions[d]->operator[](k);
201 template <
unsigned int VDimension>
204 unsigned int d,
int threadId)
206 m_Positions[d]->Erase(k);
208 m_Neighborhoods[d]->RemovePosition(k, threadId);
211 ParticlePositionRemoveEvent e;
212 e.SetThreadID(threadId);
214 e.SetPositionIndex(k);
216 this->InvokeEvent(e);
219 template <
unsigned int VDimension>
222 unsigned int d,
int threadId )
225 for (
typename std::vector<PointType>::const_iterator it= p.begin();
228 this->AddPosition(*it, d, threadId);
232 template <
unsigned int VDimension>
237 vnl_vector_fixed<double, VDimension> random;
239 for (
unsigned int i = 0; i < VDimension; i++)
240 { random[i] =
static_cast<double>(rand()); }
241 double norm = random.magnitude();
249 for (
unsigned int i = 0; i < VDimension; i++)
251 newpos[i] = this->GetPosition(idx,domain)[i] + epsilon * random[i];
253 this->GetDomain(domain)->ApplyConstraints(newpos);
254 this->AddPosition(newpos, domain, threadId);
257 template <
unsigned int VDimension>
260 double epsilon,
unsigned int domain,
int threadId)
265 std::vector<PointType> list;
269 { list.push_back(*it); }
271 for (
typename std::vector<PointType>::const_iterator it = list.begin();
272 it != list.end(); it++)
277 for (
unsigned int i = 0; i < VDimension; i++)
279 newpos[i] = (*it)[i] + epsilon * random[i];
281 this->GetDomain(domain)->ApplyConstraints(newpos);
282 this->AddPosition(newpos, domain, threadId);
286 template <
unsigned int VDimension>
291 vnl_vector_fixed<double, VDimension> random;
293 for (
unsigned int i = 0; i < VDimension; i++)
294 { random[i] =
static_cast<double>(rand()); }
295 double norm = random.magnitude();
302 for (
unsigned i = 0; i < this->GetNumberOfDomains(); i++)
304 this->SplitAllParticlesInDomain(random, epsilon, i, threadId);
308 template <
unsigned int VDimension>
314 if (attr->m_DefinedCallbacks.Event ==
true)
316 typename MemberCommand< PSMAttribute<VDimension> >::Pointer tmpcmd
317 = MemberCommand< PSMAttribute<VDimension> >::New();
321 if (attr->m_DefinedCallbacks.EventWithIndex ==
true)
323 typename MemberCommand< PSMAttribute<VDimension> >::Pointer tmpcmd
324 = MemberCommand< PSMAttribute<VDimension> >::New();
328 if (attr->m_DefinedCallbacks.DomainAddEvent ==
true)
330 typename MemberCommand< PSMAttribute<VDimension> >::Pointer tmpcmd
331 = MemberCommand< PSMAttribute<VDimension> >::New();
333 this->AddObserver(ParticleDomainAddEvent(), tmpcmd);
335 if (attr->m_DefinedCallbacks.TransformSetEvent ==
true)
337 typename MemberCommand< PSMAttribute<VDimension> >::Pointer tmpcmd
338 = MemberCommand< PSMAttribute<VDimension> >::New();
340 this->AddObserver(ParticleTransformSetEvent(), tmpcmd);
342 if (attr->m_DefinedCallbacks.PrefixTransformSetEvent ==
true)
344 typename MemberCommand< PSMAttribute<VDimension> >::Pointer tmpcmd
345 = MemberCommand< PSMAttribute<VDimension> >::New();
347 this->AddObserver(ParticlePrefixTransformSetEvent(), tmpcmd);
349 if (attr->m_DefinedCallbacks.NeighborhoodSetEvent ==
true)
351 typename MemberCommand< PSMAttribute<VDimension> >::Pointer tmpcmd
352 = MemberCommand< PSMAttribute<VDimension> >::New();
354 this->AddObserver(ParticleNeighborhoodSetEvent(), tmpcmd);
356 if (attr->m_DefinedCallbacks.PositionSetEvent ==
true)
358 typename MemberCommand< PSMAttribute<VDimension> >::Pointer tmpcmd
359 = MemberCommand< PSMAttribute<VDimension> >::New();
361 this->AddObserver(ParticlePositionSetEvent(), tmpcmd);
363 if (attr->m_DefinedCallbacks.PositionAddEvent ==
true)
365 typename MemberCommand< PSMAttribute<VDimension> >::Pointer tmpcmd
366 = MemberCommand< PSMAttribute<VDimension> >::New();
368 this->AddObserver(ParticlePositionAddEvent(), tmpcmd);
370 if (attr->m_DefinedCallbacks.PositionRemoveEvent ==
true)
372 typename MemberCommand< PSMAttribute<VDimension> >::Pointer tmpcmd
373 = MemberCommand< PSMAttribute<VDimension> >::New();
375 this->AddObserver(ParticlePositionRemoveEvent(), tmpcmd);
382 #endif //__itkPSMParticleSystem_hxx
void AddDomain(DomainType *, int threadId=0)
void SetNeighborhood(unsigned int, NeighborhoodType *, int threadId=0)
void RegisterAttribute(PSMAttribute< VDimension > *)
void AddPositionList(const std::vector< PointType > &, unsigned int d, int threadId=0)
void SetTransform(unsigned int i, const TransformType &, int threadId=0)
const PointType & AddPosition(const PointType &, unsigned int d=0, int threadId=0)
A facade class that manages interactions with a particle system.
void SetNumberOfDomains(unsigned int)
Base class for defining the domain in which a particle system exists.
void SplitAllParticles(double epsilon, int threadId=0)
An event class that specializes EventObject for the PSMParticleSystem class.
Base class for PSMParticleSystem attribute classes.
vnl_matrix_fixed< double, VDimension+1, VDimension+1 > TransformType