FeatureMeshCurvature.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2005 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
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     // get all points
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     // get all point connections
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     // compute vertex based curvatures
00091     Wm4::MeshCurvature<float> meshCurv(rMesh.CountPoints(), &(aPnts[0]), rMesh.CountFacets(), &(aIdx[0]));
00092 
00093     // get curvature information now
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 }

Generated on Wed Nov 23 19:00:11 2011 for FreeCAD by  doxygen 1.6.1