2014-02-18 12:44:41 +06:00
|
|
|
// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
|
2009-02-13 17:16:39 +05:00
|
|
|
//
|
2012-08-09 13:58:02 +06:00
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
2014-02-18 12:44:41 +06:00
|
|
|
// version 2.1 of the License, or (at your option) any later version.
|
2009-02-13 17:16:39 +05:00
|
|
|
//
|
2012-08-09 13:58:02 +06:00
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
2009-02-13 17:16:39 +05:00
|
|
|
//
|
2012-08-09 13:58:02 +06:00
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2009-02-13 17:16:39 +05:00
|
|
|
//
|
2012-08-09 13:58:02 +06:00
|
|
|
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
|
2009-02-13 17:16:39 +05:00
|
|
|
//
|
2012-08-09 13:58:02 +06:00
|
|
|
|
2008-03-07 12:45:34 +05:00
|
|
|
#include "GEOM_ShadingFace.h"
|
2014-06-09 14:56:21 +06:00
|
|
|
#include "OCC2VTK_internal.h"
|
2008-03-07 12:45:34 +05:00
|
|
|
|
|
|
|
#include <vtkObjectFactory.h>
|
|
|
|
|
|
|
|
#include <vtkPoints.h>
|
|
|
|
#include <vtkCellArray.h>
|
|
|
|
|
|
|
|
#include <vtkPolyDataMapper.h>
|
|
|
|
#include <vtkPolyData.h>
|
2013-03-01 19:10:52 +06:00
|
|
|
#include <vtkInformation.h>
|
|
|
|
#include <vtkInformationVector.h>
|
2008-03-07 12:45:34 +05:00
|
|
|
|
|
|
|
#include <BRep_Tool.hxx>
|
|
|
|
#include <Poly_Triangulation.hxx>
|
2013-03-01 19:10:52 +06:00
|
|
|
|
2008-03-07 12:45:34 +05:00
|
|
|
|
|
|
|
vtkStandardNewMacro(GEOM_ShadingFace);
|
|
|
|
|
|
|
|
GEOM_ShadingFace::GEOM_ShadingFace()
|
|
|
|
{
|
2013-03-01 19:10:52 +06:00
|
|
|
this->SetNumberOfInputPorts(0);
|
2008-03-07 12:45:34 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
GEOM_ShadingFace::~GEOM_ShadingFace()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-01 19:10:52 +06:00
|
|
|
int GEOM_ShadingFace::RequestData(vtkInformation *vtkNotUsed(request),
|
|
|
|
vtkInformationVector **vtkNotUsed(inputVector),
|
|
|
|
vtkInformationVector *outputVector)
|
2008-03-07 12:45:34 +05:00
|
|
|
{
|
2013-03-01 19:10:52 +06:00
|
|
|
vtkInformation *outInfo = outputVector->GetInformationObject(0);
|
|
|
|
vtkPolyData *aPolyData = vtkPolyData::SafeDownCast(
|
|
|
|
outInfo->Get(vtkDataObject::DATA_OBJECT()));
|
|
|
|
|
2008-03-07 12:45:34 +05:00
|
|
|
aPolyData->Allocate();
|
|
|
|
vtkPoints* aPts = vtkPoints::New();
|
|
|
|
aPolyData->SetPoints(aPts);
|
|
|
|
aPts->Delete();
|
|
|
|
|
2014-06-09 14:56:21 +06:00
|
|
|
TFaceSet::Iterator anIter(myData->myFaceSet);
|
2008-03-07 12:45:34 +05:00
|
|
|
for(; anIter.More(); anIter.Next()){
|
|
|
|
const TopoDS_Face& aFace = anIter.Value();
|
|
|
|
OCC2VTK(aFace,aPolyData,aPts);
|
|
|
|
}
|
2013-03-01 19:10:52 +06:00
|
|
|
return 1;
|
2008-03-07 12:45:34 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GEOM_ShadingFace::
|
|
|
|
OCC2VTK(const TopoDS_Face& theFace,
|
|
|
|
vtkPolyData* thePolyData,
|
|
|
|
vtkPoints* thePts)
|
|
|
|
{
|
|
|
|
TopLoc_Location aLoc;
|
|
|
|
Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(theFace,aLoc);
|
|
|
|
if(aPoly.IsNull())
|
|
|
|
return;
|
|
|
|
else{
|
|
|
|
gp_Trsf myTransf;
|
|
|
|
Standard_Boolean identity = true;
|
|
|
|
if(!aLoc.IsIdentity()){
|
|
|
|
identity = false;
|
|
|
|
myTransf = aLoc.Transformation();
|
2012-08-09 13:58:02 +06:00
|
|
|
}
|
2008-03-07 12:45:34 +05:00
|
|
|
|
|
|
|
Standard_Integer i;
|
|
|
|
int aNbOfNodes = thePts->GetNumberOfPoints();
|
|
|
|
const TColgp_Array1OfPnt& Nodes = aPoly->Nodes();
|
|
|
|
Standard_Integer nbNodesInFace = aPoly->NbNodes();
|
|
|
|
for(i = 1; i <= nbNodesInFace; i++) {
|
|
|
|
gp_Pnt P = Nodes(i);
|
|
|
|
if(!identity)
|
|
|
|
P.Transform(myTransf);
|
|
|
|
thePts->InsertNextPoint(P.X(),P.Y(),P.Z());
|
|
|
|
}
|
|
|
|
|
|
|
|
const Poly_Array1OfTriangle& Triangles = aPoly->Triangles();
|
|
|
|
Standard_Integer nbTriInFace = aPoly->NbTriangles();
|
|
|
|
for(i = 1; i <= nbTriInFace; i++){
|
|
|
|
// Get the triangle
|
|
|
|
Standard_Integer N1,N2,N3;
|
|
|
|
Triangles(i).Get(N1,N2,N3);
|
|
|
|
N1 += aNbOfNodes - 1;
|
|
|
|
N2 += aNbOfNodes - 1;
|
|
|
|
N3 += aNbOfNodes - 1;
|
|
|
|
vtkIdType anIds[3] = {N1, N2, N3};
|
|
|
|
thePolyData->InsertNextCell(VTK_TRIANGLE,3,anIds);
|
|
|
|
}
|
|
|
|
}
|
2009-02-13 17:16:39 +05:00
|
|
|
}
|