0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / IVtkVTK / IVtkVTK_ShapeData.cxx
CommitLineData
913a4c4a 1// Created on: 2011-10-14
2// Created by: Roman KOZLOV
3// Copyright (c) 2011-2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#include <IVtkVTK_ShapeData.hxx>
a9660929 17
18// prevent disabling some MSVC warning messages by VTK headers
19#ifdef _MSC_VER
20#pragma warning(push)
21#endif
913a4c4a 22#include <vtkCellData.h>
23#include <vtkDoubleArray.h>
a2f76b15 24#include <vtkIdList.h>
913a4c4a 25#include <vtkPoints.h>
26#include <vtkPolyData.h>
a9660929 27#ifdef _MSC_VER
28#pragma warning(pop)
29#endif
913a4c4a 30
92efcf78 31IMPLEMENT_STANDARD_RTTIEXT(IVtkVTK_ShapeData,IVtk_IShapeData)
32
913a4c4a 33//================================================================
34// Function : Constructor
35// Purpose :
36//================================================================
37IVtkVTK_ShapeData::IVtkVTK_ShapeData()
913a4c4a 38{
c16915c7 39 myPolyData = vtkSmartPointer<vtkPolyData>::New();
913a4c4a 40 myPolyData->Allocate();
a2f76b15 41 myPolyData->SetPoints (vtkSmartPointer<vtkPoints>::New());
913a4c4a 42
c16915c7 43 mySubShapeIDs = vtkSmartPointer<vtkIdTypeArray>::New();
68df8478 44 mySubShapeIDs->SetName (IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS());
913a4c4a 45 mySubShapeIDs->SetNumberOfComponents (1);
46 myPolyData->GetCellData()->AddArray (mySubShapeIDs);
47
c16915c7 48 myMeshTypes = vtkSmartPointer<vtkIdTypeArray>::New();
68df8478 49 myMeshTypes->SetName (IVtkVTK_ShapeData::ARRNAME_MESH_TYPES());
913a4c4a 50 myMeshTypes->SetNumberOfComponents (1);
51 myPolyData->GetCellData()->AddArray (myMeshTypes);
52}
53
54//================================================================
55// Function : Destructor
56// Purpose :
57//================================================================
58IVtkVTK_ShapeData::~IVtkVTK_ShapeData()
59{ }
60
61//================================================================
62// Function : InsertCoordinate
63// Purpose :
64//================================================================
65IVtk_PointId IVtkVTK_ShapeData::InsertCoordinate (double theX,
66 double theY,
67 double theZ)
68{
69 return myPolyData->GetPoints()->InsertNextPoint (theX, theY, theZ);
70}
71
72//================================================================
73// Function : InsertVertex
74// Purpose :
75//================================================================
76void IVtkVTK_ShapeData::InsertVertex (const IVtk_IdType theShapeID,
77 const IVtk_PointId thePointId,
78 const IVtk_MeshType theMeshType)
79{
80 vtkIdType aPointIdVTK = thePointId;
81 myPolyData->InsertNextCell (VTK_VERTEX, 1, &aPointIdVTK);
e607bd3e 82 insertNextSubShapeId (theShapeID, theMeshType);
913a4c4a 83}
84
85//================================================================
86// Function : InsertLine
87// Purpose :
88//================================================================
89void IVtkVTK_ShapeData::InsertLine (const IVtk_IdType theShapeID,
90 const IVtk_PointId thePointId1,
91 const IVtk_PointId thePointId2,
92 const IVtk_MeshType theMeshType)
93{
94 vtkIdType aPoints[2] = { thePointId1, thePointId2 };
95 myPolyData->InsertNextCell (VTK_LINE, 2, aPoints);
e607bd3e 96 insertNextSubShapeId (theShapeID, theMeshType);
913a4c4a 97}
98
99//================================================================
100// Function : InsertLine
101// Purpose :
102//================================================================
103void IVtkVTK_ShapeData::InsertLine (const IVtk_IdType theShapeID,
104 const IVtk_PointIdList* thePointIds,
105 const IVtk_MeshType theMeshType)
106{
107 if (!thePointIds->IsEmpty())
108 {
a2f76b15 109 vtkSmartPointer<vtkIdList> anIdList = vtkSmartPointer<vtkIdList>::New();
913a4c4a 110 // Fill the vtk id list by ids from IVtk_PointIdList.
111 IVtk_PointIdList::Iterator anIterOfIds =
112 IVtk_PointIdList::Iterator(*thePointIds);
113 anIdList->Allocate(thePointIds->Extent());
114 for(; anIterOfIds.More(); anIterOfIds.Next())
115 {
116 anIdList->InsertNextId (anIterOfIds.Value());
117 }
118
119 myPolyData->InsertNextCell (VTK_POLY_LINE, anIdList);
e607bd3e 120 insertNextSubShapeId (theShapeID, theMeshType);
913a4c4a 121 }
122}
123
124//================================================================
125// Function : InsertTriangle
126// Purpose :
127//================================================================
128void IVtkVTK_ShapeData::InsertTriangle (const IVtk_IdType theShapeID,
129 const IVtk_PointId thePointId1,
130 const IVtk_PointId thePointId2,
131 const IVtk_PointId thePointId3,
132 const IVtk_MeshType theMeshType)
133{
134 vtkIdType aPoints[3] = { thePointId1, thePointId2, thePointId3 };
135 myPolyData->InsertNextCell (VTK_TRIANGLE, 3, aPoints);
e607bd3e 136 insertNextSubShapeId (theShapeID, theMeshType);
913a4c4a 137}