Back to index

salome-geom  6.5.0
GEOM_ShadingFace.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "GEOM_ShadingFace.h" 
00021  
00022 #include <vtkObjectFactory.h> 
00023  
00024 #include <vtkPoints.h> 
00025 #include <vtkCellArray.h> 
00026 
00027 #include <vtkPolyDataMapper.h>  
00028 #include <vtkPolyData.h>  
00029 
00030 #include <BRep_Tool.hxx>
00031 #include <Poly_Triangulation.hxx>
00032  
00033 
00034 vtkStandardNewMacro(GEOM_ShadingFace);
00035  
00036 GEOM_ShadingFace::GEOM_ShadingFace() 
00037 { 
00038 } 
00039  
00040 GEOM_ShadingFace::~GEOM_ShadingFace() 
00041 { 
00042 } 
00043  
00044 void
00045 GEOM_ShadingFace:: 
00046 Execute()
00047 {
00048   vtkPolyData* aPolyData = GetOutput();
00049   aPolyData->Allocate();
00050   vtkPoints* aPts = vtkPoints::New();
00051   aPolyData->SetPoints(aPts);
00052   aPts->Delete();
00053 
00054   TFaceSet::Iterator anIter(myFaceSet);
00055   for(; anIter.More(); anIter.Next()){
00056     const TopoDS_Face& aFace = anIter.Value();
00057     OCC2VTK(aFace,aPolyData,aPts);
00058   }
00059 }
00060 
00061 void  
00062 GEOM_ShadingFace:: 
00063 OCC2VTK(const TopoDS_Face& theFace,  
00064         vtkPolyData* thePolyData, 
00065         vtkPoints* thePts) 
00066 {
00067   TopLoc_Location aLoc;
00068   Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(theFace,aLoc);
00069   if(aPoly.IsNull()) 
00070     return;
00071   else{
00072     gp_Trsf myTransf;
00073     Standard_Boolean identity = true;
00074     if(!aLoc.IsIdentity()){
00075       identity = false;
00076       myTransf = aLoc.Transformation();
00077     }           
00078       
00079     Standard_Integer i; 
00080     int aNbOfNodes = thePts->GetNumberOfPoints();
00081     const TColgp_Array1OfPnt& Nodes = aPoly->Nodes();
00082     Standard_Integer nbNodesInFace = aPoly->NbNodes(); 
00083     for(i = 1; i <= nbNodesInFace; i++) {
00084       gp_Pnt P = Nodes(i);
00085       if(!identity) 
00086         P.Transform(myTransf);
00087       thePts->InsertNextPoint(P.X(),P.Y(),P.Z());
00088     }
00089 
00090     const Poly_Array1OfTriangle& Triangles = aPoly->Triangles();
00091     Standard_Integer nbTriInFace = aPoly->NbTriangles();
00092     for(i = 1; i <= nbTriInFace; i++){
00093       // Get the triangle
00094       Standard_Integer N1,N2,N3;
00095       Triangles(i).Get(N1,N2,N3);
00096       N1 += aNbOfNodes - 1;
00097       N2 += aNbOfNodes - 1;
00098       N3 += aNbOfNodes - 1;
00099       vtkIdType anIds[3] = {N1, N2, N3};
00100       thePolyData->InsertNextCell(VTK_TRIANGLE,3,anIds);
00101     }
00102   } 
00103 }