forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkOpenGLMoleculeMapper.cxx
130 lines (109 loc) · 4.55 KB
/
vtkOpenGLMoleculeMapper.cxx
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*=========================================================================
Program: Visualization Toolkit
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkOpenGLMoleculeMapper.h"
#include "vtkOpenGLSphereMapper.h"
#include "vtkOpenGLStickMapper.h"
#include "vtkEventForwarderCommand.h"
#include "vtkGlyph3DMapper.h"
#include "vtkLookupTable.h"
#include "vtkObjectFactory.h"
#include "vtkPeriodicTable.h"
#include "vtkTrivialProducer.h"
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkOpenGLMoleculeMapper)
//----------------------------------------------------------------------------
vtkOpenGLMoleculeMapper::vtkOpenGLMoleculeMapper()
{
// Setup glyph mappers
vtkNew<vtkLookupTable> lut;
this->PeriodicTable->GetDefaultLUT(lut.GetPointer());
this->FastAtomMapper->SetLookupTable(lut.GetPointer());
this->FastAtomMapper->SetScalarRange
(0, this->PeriodicTable->GetNumberOfElements());
this->FastAtomMapper->SetColorModeToMapScalars();
this->FastAtomMapper->SetScalarModeToUsePointFieldData();
// Forward commands to instance mappers
vtkNew<vtkEventForwarderCommand> cb;
cb->SetTarget(this);
this->FastAtomMapper->AddObserver(vtkCommand::StartEvent, cb.GetPointer());
this->FastAtomMapper->AddObserver(vtkCommand::EndEvent, cb.GetPointer());
this->FastAtomMapper->AddObserver(vtkCommand::ProgressEvent,
cb.GetPointer());
this->FastBondMapper->AddObserver(vtkCommand::StartEvent, cb.GetPointer());
this->FastBondMapper->AddObserver(vtkCommand::EndEvent, cb.GetPointer());
this->FastBondMapper->AddObserver(vtkCommand::ProgressEvent,
cb.GetPointer());
// Connect the trivial producers to forward the glyph polydata
this->FastAtomMapper->SetInputConnection
(this->AtomGlyphPointOutput->GetOutputPort());
this->FastBondMapper->SetInputConnection
(this->BondGlyphPointOutput->GetOutputPort());
}
vtkOpenGLMoleculeMapper::~vtkOpenGLMoleculeMapper()
{
}
//----------------------------------------------------------------------------
void vtkOpenGLMoleculeMapper::Render(vtkRenderer *ren, vtkActor *act )
{
// Update cached polydata if needed
this->UpdateGlyphPolyData();
// Pass rendering call on
if (this->RenderAtoms)
{
this->FastAtomMapper->Render(ren, act);
// this->AtomGlyphMapper->Render(ren, act);
}
if (this->RenderBonds)
{
this->FastBondMapper->Render(ren, act);
// this->BondGlyphMapper->Render(ren, act);
}
}
//----------------------------------------------------------------------------
void vtkOpenGLMoleculeMapper::ReleaseGraphicsResources(vtkWindow *w)
{
this->FastAtomMapper->ReleaseGraphicsResources(w);
this->FastBondMapper->ReleaseGraphicsResources(w);
this->Superclass::ReleaseGraphicsResources(w);
}
//----------------------------------------------------------------------------
// Generate scale and position information for each atom sphere
void vtkOpenGLMoleculeMapper::UpdateAtomGlyphPolyData()
{
this->Superclass::UpdateAtomGlyphPolyData();
this->FastAtomMapper->SelectColorArray("Atomic Numbers");
this->FastAtomMapper->SetScaleArray("Scale Factors");
}
//----------------------------------------------------------------------------
// Generate position, scale, and orientation vectors for each bond cylinder
void vtkOpenGLMoleculeMapper::UpdateBondGlyphPolyData()
{
switch(this->BondColorMode)
{
case SingleColor:
this->FastBondMapper->SetColorModeToDefault();
this->FastBondMapper->SetScalarModeToUsePointData();
break;
default:
case DiscreteByAtom:
vtkNew<vtkLookupTable> lut;
this->PeriodicTable->GetDefaultLUT(lut.GetPointer());
this->FastBondMapper->SetLookupTable(lut.GetPointer());
this->FastBondMapper->SetScalarRange
(0, this->PeriodicTable->GetNumberOfElements());
this->FastBondMapper->SetScalarModeToUsePointData();
break;
}
// Setup glypher
this->Superclass::UpdateBondGlyphPolyData();
this->FastBondMapper->SetScaleArray("Scale Factors");
this->FastBondMapper->SetOrientationArray("Orientation Vectors");
this->FastBondMapper->SetSelectionIdArray("Selection Ids");
}