AnimatLab  2
Test
OsgMeshMinVertexDistanceVisitor.cpp
1 #include "StdAfx.h"
2 #include "OsgMeshMinVertexDistanceVisitor.h"
3 
4 
5 namespace OsgAnimatSim
6 {
7  namespace Visualization
8  {
9 
10 
11 void OsgMeshMinVertexDistanceVisitor::FindMinVertex(osg::Geometry *osgGeom, osg::Vec3Array *aryVert)
12 {
13  float fltDist;
14 
15  //First make a copy of the vertex array so we can mess with it.
16  int iLen = aryVert->size();
17  for(int iP=0; iP<iLen; iP++)
18  for(int iQ=0; iQ<iLen; iQ++)
19  if(iQ != iP)
20  {
21  osg::Vec3 vP = ((*aryVert)[iP]);
22  osg::Vec3 vQ = ((*aryVert)[iQ]);
23 
24  fltDist = Std_CalculateDistance(vP.x(), vP.y(), vP.z(), vQ.x(), vQ.y(), vQ.z());
25  //I am making 0.05f a hard-limit for the minimum distance. I don't want vertex sphere radius smaller than this.
26  if(fltDist > 0.05f && fltDist < m_fltMinVertDist || m_fltMinVertDist == -1)
27  {
28  m_fltMinVertDist = fltDist;
29  m_lpGeom = osgGeom;
30  m_iP = iP;
31  m_iQ = iQ;
32  }
33  }
34 }
35 
36 void OsgMeshMinVertexDistanceVisitor::apply(osg::Node &node)
37 {
38  osg::Geode *osgGeode = dynamic_cast<osg::Geode *>(&node);
39 
40  if(osgGeode && osgGeode->getNumDrawables() > 0)
41  {
42  int iDrawCount = osgGeode->getNumDrawables();
43 
44  for(int iDraw=0; iDraw<iDrawCount; iDraw++)
45  {
46  osg::Geometry *osgGeom = dynamic_cast<osg::Geometry *>(osgGeode->getDrawable(iDraw));
47 
48  if(osgGeom)
49  {
50  osg::ref_ptr<osg::Vec3Array> aryVert = dynamic_cast<osg::Vec3Array*>(osgGeom->getVertexArray());
51  FindMinVertex(osgGeom, aryVert.get());
52  }
53  }
54  }
55 
56  traverse(node);
57 }
58 
59  }// end Visualization
60 }//end OsgAnimatSim
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
double Std_CalculateDistance(CStdIPoint &ptA, CStdIPoint &ptB)
Calculates the distance between two points.