// Created on: 2004-06-10
// Created by: Alexander SOLOVYOV
-// Copyright (c) 2004-2012 OPEN CASCADE SAS
+// Copyright (c) 2004-2014 OPEN CASCADE SAS
//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+#include <XSDRAWSTLVRML_DataSource.hxx>
-#include <XSDRAWSTLVRML_DataSource.ixx>
-
-#include <StlMesh_SequenceOfMeshTriangle.hxx>
-#include <StlMesh_MeshTriangle.hxx>
+#include <Precision.hxx>
+#include <Standard_Type.hxx>
#include <TColgp_SequenceOfXYZ.hxx>
-#include <TColStd_DataMapOfIntegerReal.hxx>
#include <TColStd_DataMapOfIntegerInteger.hxx>
+#include <TColStd_DataMapOfIntegerReal.hxx>
+
+IMPLEMENT_STANDARD_RTTIEXT(XSDRAWSTLVRML_DataSource,MeshVS_DataSource)
//================================================================
// Function : Constructor
// Purpose :
//================================================================
-XSDRAWSTLVRML_DataSource::XSDRAWSTLVRML_DataSource( const Handle( StlMesh_Mesh )& aMesh )
+XSDRAWSTLVRML_DataSource::XSDRAWSTLVRML_DataSource (const Handle(Poly_Triangulation)& aMesh)
{
myMesh = aMesh;
if( !myMesh.IsNull() )
{
- const TColgp_SequenceOfXYZ& aCoords = myMesh->Vertices();
+ const TColgp_Array1OfPnt& aCoords = myMesh->Nodes();
Standard_Integer len = aCoords.Length(), i, j;
myNodeCoords = new TColStd_HArray2OfReal(1, len, 1, 3);
- cout << "Nodes : " << len << endl;
+ std::cout << "Nodes : " << len << std::endl;
gp_XYZ xyz;
for( i = 1; i <= len; i++ )
{
myNodes.Add( i );
- xyz = aCoords(i);
+ xyz = aCoords(i).XYZ();
myNodeCoords->SetValue(i, 1, xyz.X());
myNodeCoords->SetValue(i, 2, xyz.Y());
myNodeCoords->SetValue(i, 3, xyz.Z());
}
- const StlMesh_SequenceOfMeshTriangle& aSeq = myMesh->Triangles();
+ const Poly_Array1OfTriangle& aSeq = myMesh->Triangles();
len = aSeq.Length();
myElemNormals = new TColStd_HArray2OfReal(1, len, 1, 3);
myElemNodes = new TColStd_HArray2OfInteger(1, len, 1, 3);
- cout << "Elements : " << len << endl;
+ std::cout << "Elements : " << len << std::endl;
for( i = 1; i <= len; i++ )
{
myElements.Add( i );
- Handle( StlMesh_MeshTriangle ) aTriangle = aSeq.Value( i );
- Standard_Integer V[3]; Standard_Real nx, ny, nz;
- aTriangle->GetVertexAndOrientation( V[0], V[1], V[2], nx, ny, nz );
+ const Poly_Triangle& aTri = aSeq(i);
+
+ Standard_Integer V[3];
+ aTri.Get (V[0], V[1], V[2]);
+
+ const gp_Pnt aP1 = aCoords (V[0]);
+ const gp_Pnt aP2 = aCoords (V[1]);
+ const gp_Pnt aP3 = aCoords (V[2]);
+
+ gp_Vec aV1(aP1, aP2);
+ gp_Vec aV2(aP2, aP3);
+
+ gp_Vec aN = aV1.Crossed(aV2);
+ if (aN.SquareMagnitude() > Precision::SquareConfusion())
+ aN.Normalize();
+ else
+ aN.SetCoord(0.0, 0.0, 0.0);
for( j = 0; j < 3; j++ )
{
myElemNodes->SetValue(i, j+1, V[j]);
}
- myElemNormals->SetValue(i, 1, nx);
- myElemNormals->SetValue(i, 2, ny);
- myElemNormals->SetValue(i, 3, nz);
+ myElemNormals->SetValue (i, 1, aN.X());
+ myElemNormals->SetValue (i, 2, aN.Y());
+ myElemNormals->SetValue (i, 3, aN.Z());
}
}
- cout << "Construction is finished" << endl;
+ std::cout << "Construction is finished" << std::endl;
}
//================================================================
Standard_Boolean XSDRAWSTLVRML_DataSource::GetNodesByElement
( const Standard_Integer ID,
TColStd_Array1OfInteger& theNodeIDs,
- Standard_Integer& theNbNodes ) const
+ Standard_Integer& /*theNbNodes*/ ) const
{
if( myMesh.IsNull() )
return Standard_False;