0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[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>
913a4c4a 17#include <vtkCellData.h>
18#include <vtkDoubleArray.h>
a2f76b15 19#include <vtkIdList.h>
913a4c4a 20#include <vtkIdTypeArray.h>
21#include <vtkPoints.h>
22#include <vtkPolyData.h>
23
92efcf78 24IMPLEMENT_STANDARD_RTTIEXT(IVtkVTK_ShapeData,IVtk_IShapeData)
25
913a4c4a 26const char* const IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS = "SUBSHAPE_IDS";
27
28const char* const IVtkVTK_ShapeData::ARRNAME_MESH_TYPES = "MESH_TYPES";
29
30//! Handle implementation
913a4c4a 31
32
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();
913a4c4a 44 mySubShapeIDs->SetName (IVtkVTK_ShapeData::ARRNAME_SUBSHAPE_IDS);
45 mySubShapeIDs->SetNumberOfComponents (1);
46 myPolyData->GetCellData()->AddArray (mySubShapeIDs);
47
c16915c7 48 myMeshTypes = vtkSmartPointer<vtkIdTypeArray>::New();
913a4c4a 49 myMeshTypes->SetName (IVtkVTK_ShapeData::ARRNAME_MESH_TYPES);
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);
82 const vtkIdType aShapeIDVTK = theShapeID;
83 mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
84 const vtkIdType aType = theMeshType;
85 myMeshTypes->InsertNextTupleValue (&aType);
86}
87
88//================================================================
89// Function : InsertLine
90// Purpose :
91//================================================================
92void IVtkVTK_ShapeData::InsertLine (const IVtk_IdType theShapeID,
93 const IVtk_PointId thePointId1,
94 const IVtk_PointId thePointId2,
95 const IVtk_MeshType theMeshType)
96{
97 vtkIdType aPoints[2] = { thePointId1, thePointId2 };
98 myPolyData->InsertNextCell (VTK_LINE, 2, aPoints);
99 const vtkIdType aShapeIDVTK = theShapeID;
100 mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
101 const vtkIdType aType = theMeshType;
102 myMeshTypes->InsertNextTupleValue (&aType);
103}
104
105//================================================================
106// Function : InsertLine
107// Purpose :
108//================================================================
109void IVtkVTK_ShapeData::InsertLine (const IVtk_IdType theShapeID,
110 const IVtk_PointIdList* thePointIds,
111 const IVtk_MeshType theMeshType)
112{
113 if (!thePointIds->IsEmpty())
114 {
a2f76b15 115 vtkSmartPointer<vtkIdList> anIdList = vtkSmartPointer<vtkIdList>::New();
913a4c4a 116 // Fill the vtk id list by ids from IVtk_PointIdList.
117 IVtk_PointIdList::Iterator anIterOfIds =
118 IVtk_PointIdList::Iterator(*thePointIds);
119 anIdList->Allocate(thePointIds->Extent());
120 for(; anIterOfIds.More(); anIterOfIds.Next())
121 {
122 anIdList->InsertNextId (anIterOfIds.Value());
123 }
124
125 myPolyData->InsertNextCell (VTK_POLY_LINE, anIdList);
126 const vtkIdType aShapeIDVTK = theShapeID;
127 mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
128 const vtkIdType aType = theMeshType;
129 myMeshTypes->InsertNextTupleValue (&aType);
913a4c4a 130 }
131}
132
133//================================================================
134// Function : InsertTriangle
135// Purpose :
136//================================================================
137void IVtkVTK_ShapeData::InsertTriangle (const IVtk_IdType theShapeID,
138 const IVtk_PointId thePointId1,
139 const IVtk_PointId thePointId2,
140 const IVtk_PointId thePointId3,
141 const IVtk_MeshType theMeshType)
142{
143 vtkIdType aPoints[3] = { thePointId1, thePointId2, thePointId3 };
144 myPolyData->InsertNextCell (VTK_TRIANGLE, 3, aPoints);
145 const vtkIdType aShapeIDVTK = theShapeID;
146 mySubShapeIDs->InsertNextTupleValue (&aShapeIDVTK);
147 const vtkIdType aType = theMeshType;
148 myMeshTypes->InsertNextTupleValue (&aType);
149}