imstkVTKdebugLinesRenderDelegate.cpp 2.81 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*=========================================================================

Library: iMSTK

Copyright (c) Kitware, Inc. & Center for Modeling, Simulation,
& Imaging in Medicine, Rensselaer Polytechnic Institute.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0.txt

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=========================================================================*/

#include "imstkVTKdebugLinesRenderDelegate.h"

#include "imstkSurfaceMesh.h"

#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkPoints.h>
#include <vtkDoubleArray.h>
#include <vtkCellArray.h>
#include <vtkFloatArray.h>
#include <vtkPointData.h>
#include <vtkProperty.h>
#include <vtkOpenGLPolyDataMapper.h>
#include <vtkTrivialProducer.h>
36
#include <vtkLine.h>
37
38
39
40
41
42
43
44
45
46
47
48
49

namespace imstk
{
VTKdbgLinesRenderDelegate::VTKdbgLinesRenderDelegate(std::shared_ptr<DebugRenderLines> renderLines) :
    m_Lines(renderLines),
    m_mappedVertexArray(vtkSmartPointer<vtkDoubleArray>::New())
{
    // Map vertices
    StdVectorOfVec3d& triVertData = renderLines->getVertexPositionsNonConst();
    m_mappedVertexArray->SetNumberOfComponents(3);
    double* vertData = reinterpret_cast<double*>(triVertData.data());
    m_mappedVertexArray->SetArray(vertData, triVertData.size() * 3, 1);

50
51
52
    // Create lines polydata
    auto linesPolyData = vtkSmartPointer<vtkPolyData>::New();

53
54
55
56
    // Create points
    auto points = vtkSmartPointer<vtkPoints>::New();
    points->SetNumberOfPoints(triVertData.size());
    points->SetData(m_mappedVertexArray);
57
    linesPolyData->SetPoints(points);
58
59

    // Create cells
60
61
    auto lines = vtkSmartPointer<vtkCellArray>::New();
    for (unsigned int i = 0; i < triVertData.size() - 1; i += 2)
62
    {
63
64
65
        auto l = vtkSmartPointer<vtkLine>::New();
        l->GetPointIds()->SetId(0, i);
        l->GetPointIds()->SetId(1, i + 1);
66

67
68
69
        lines->InsertNextCell(l);
    }
    linesPolyData->SetLines(lines);
70
71
72

    // Create connection source
    auto source = vtkSmartPointer<vtkTrivialProducer>::New();
73
    source->SetOutput(linesPolyData);
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
    m_Lines->setDataModifiedFlag(false);

    // Update Transform, Render Properties
    this->updateDataSource();
    this->updateActorProperties();

    this->setUpMapper(source->GetOutputPort(), false, m_Lines->getRenderMaterial());
}

void
VTKdbgLinesRenderDelegate::updateDataSource()
{
    if (m_Lines->isModified())
    {
        m_mappedVertexArray->Modified();
    }
}
} // imstk