FeatureMeshCurvature.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 #endif
00027
00028 #include <Base/Console.h>
00029 #include <Base/Exception.h>
00030 #include <Base/Matrix.h>
00031 #include <Base/Sequencer.h>
00032 #include <Mod/Mesh/App/WildMagic4/Wm4Vector3.h>
00033 #include <Mod/Mesh/App/WildMagic4/Wm4MeshCurvature.h>
00034 #include "FeatureMeshCurvature.h"
00035 #include "MeshFeature.h"
00036
00037 #include "Core/Elements.h"
00038 #include "Core/Iterator.h"
00039
00040
00041
00042 using namespace Mesh;
00043 using namespace MeshCore;
00044
00045 PROPERTY_SOURCE(Mesh::Curvature, App::DocumentObject)
00046
00047
00048 Curvature::Curvature(void)
00049 {
00050 ADD_PROPERTY(Source,(0));
00051 ADD_PROPERTY(CurvInfo, (CurvatureInfo()));
00052 }
00053
00054 short Curvature::mustExecute() const
00055 {
00056 if (Source.isTouched())
00057 return 1;
00058 if (Source.getValue() && Source.getValue()->isTouched())
00059 return 1;
00060 return 0;
00061 }
00062
00063 App::DocumentObjectExecReturn *Curvature::execute(void)
00064 {
00065 Mesh::Feature *pcFeat = dynamic_cast<Mesh::Feature*>(Source.getValue());
00066 if(!pcFeat || pcFeat->isError()) {
00067 return new App::DocumentObjectExecReturn("No mesh object attached.");
00068 }
00069
00070
00071 const MeshKernel& rMesh = pcFeat->Mesh.getValue().getKernel();
00072 std::vector< Wm4::Vector3<float> > aPnts;
00073 aPnts.reserve(rMesh.CountPoints());
00074 MeshPointIterator cPIt( rMesh );
00075 for (cPIt.Init(); cPIt.More(); cPIt.Next()) {
00076 Wm4::Vector3<float> cP(cPIt->x, cPIt->y, cPIt->z);
00077 aPnts.push_back(cP);
00078 }
00079
00080
00081 std::vector<int> aIdx;
00082 aIdx.reserve(3*rMesh.CountFacets());
00083 const std::vector<MeshFacet>& raFts = rMesh.GetFacets();
00084 for (std::vector<MeshFacet>::const_iterator jt = raFts.begin(); jt != raFts.end(); ++jt) {
00085 for (int i=0; i<3; i++) {
00086 aIdx.push_back((int)jt->_aulPoints[i]);
00087 }
00088 }
00089
00090
00091 Wm4::MeshCurvature<float> meshCurv(rMesh.CountPoints(), &(aPnts[0]), rMesh.CountFacets(), &(aIdx[0]));
00092
00093
00094 const Wm4::Vector3<float>* aMaxCurvDir = meshCurv.GetMaxDirections();
00095 const Wm4::Vector3<float>* aMinCurvDir = meshCurv.GetMinDirections();
00096 const float* aMaxCurv = meshCurv.GetMaxCurvatures();
00097 const float* aMinCurv = meshCurv.GetMinCurvatures();
00098
00099 std::vector<CurvatureInfo> values(rMesh.CountPoints());
00100 for (unsigned long i=0; i<rMesh.CountPoints(); i++) {
00101 CurvatureInfo ci;
00102 ci.cMaxCurvDir = Base::Vector3f(aMaxCurvDir[i].X(), aMaxCurvDir[i].Y(), aMaxCurvDir[i].Z());
00103 ci.cMinCurvDir = Base::Vector3f(aMinCurvDir[i].X(), aMinCurvDir[i].Y(), aMinCurvDir[i].Z());
00104 ci.fMaxCurvature = aMaxCurv[i];
00105 ci.fMinCurvature = aMinCurv[i];
00106 values[i] = ci;
00107 }
00108
00109 CurvInfo.setValues(values);
00110
00111 return App::DocumentObject::StdReturn;
00112 }