File: Form_Test.cpp

package info (click to toggle)
vtk 5.8.0-13
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 130,524 kB
  • sloc: cpp: 1,129,256; ansic: 708,203; tcl: 48,526; python: 20,875; xml: 6,779; yacc: 4,208; perl: 3,121; java: 2,788; lex: 931; sh: 660; asm: 471; makefile: 299
file content (208 lines) | stat: -rw-r--r-- 6,505 bytes parent folder | download | duplicates (8)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
//---------------------------------------------------------------------------
//
// Demo Borland + vtk Project,
//
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

//---------------------------------------------------------------------------
#include "Form_Test.h"
//
#include "vtkActor.h"
#include "vtkAssemblyPath.h"
#include "vtkAssemblyNode.h"
#include "vtkElevationFilter.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkShrinkPolyData.h"
#include "vtkSphereSource.h"
#include "vtkTriangleFilter.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)
#pragma link "vtkBorlandRenderWindow"
#pragma resource "*.dfm"

TVTK_Form *VTK_Form;
//---------------------------------------------------------------------------
__fastcall TVTK_Form::TVTK_Form(TComponent* Owner) : TForm(Owner)
{
  shrink = NULL;
}
//---------------------------------------------------------------------------
void __fastcall TVTK_Form::FormDestroy(TObject *Sender)
{
  if (shrink)
    {
    shrink->Delete();
    }

  // The release of graphics resources is required here in
  // the event that an actor is switched between solid
  // and wireframe representations.  This cannot be implemented within
  // vtkBorlandRenderWindow, since ReleaseGraphicsResources, when called
  // by a vtkProp's mapper, will cause the internal vtkWin32OpenGLRenderWindow
  // to fail during MakeCurrent.

  vtkRenderer* ren1 = vtkWindow1->GetRenderer();
  vtkRenderWindow* renwin1 = vtkWindow1->GetRenderWindow();

  vtkPropCollection* collection = ren1->GetViewProps();
  if(collection)
    {
    collection->InitTraversal();
    for (int i = 0; i < collection->GetNumberOfItems(); i++)
      {
      vtkActor *actor = vtkActor::SafeDownCast(collection->GetNextProp());
      if(actor)
        {
        actor->ReleaseGraphicsResources(renwin1);
        ren1->RemoveViewProp(actor);
        }
      }
    }
}
//---------------------------------------------------------------------------
void __fastcall TVTK_Form::HeaderControl1SectionClick(THeaderControl *HeaderControl, THeaderSection *Section)
{
  if (Section->Text=="Mode")
    {
    TPoint p = HeaderControl->ClientToScreen(TPoint(0,0));
    ModeMenu->Popup(p.x + Section->Left, p.y - 0);
    }
  else if (Section->Text=="Window")
    {
    TPoint p = HeaderControl->ClientToScreen(TPoint(0,0));
    WindowMenu->Popup(p.x + Section->Left, p.y - 0);
    }
}
//---------------------------------------------------------------------------
void __fastcall TVTK_Form::TrackBallMode1Click(TObject *Sender)
{
  if (Sender==JoystickMode1)
    {
    vtkWindow1->SetInteractorMode(IM_JoystickCamera);
    JoystickMode1->Checked = true;
    }
  if (Sender==TrackBallMode1)
    {
    vtkWindow1->SetInteractorMode(IM_TrackballCamera);
    TrackBallMode1->Checked = true;
    }
  if (Sender==FlightMode1)
    {
    vtkWindow1->SetInteractorMode(IM_Flight);
    FlightMode1->Checked = true;
    }
}
//---------------------------------------------------------------------------
void __fastcall TVTK_Form::BackgroundColour1Click(TObject *Sender)
{
  if (!backgroundcolor->Execute())
    {
    return;
    }
  DWORD  L = ColorToRGB(backgroundcolor->Color);
  double rgb[3] = { GetRValue(L)/255.0, GetGValue(L)/255.0, GetBValue(L)/255.0 };
  vtkWindow1->GetRenderer()->SetBackground(rgb);
  vtkWindow1->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TVTK_Form::ResetCamera1Click(TObject *Sender)
{
  vtkWindow1->GetRenderer()->ResetCamera();
  vtkWindow1->Invalidate();
}
//---------------------------------------------------------------------------
//
//
// Here's a demo
//
//
//---------------------------------------------------------------------------
void __fastcall TVTK_Form::bc1Click(TObject *Sender)
{
  if (shrink)
    {
    return;
    }

  vtkSphereSource *sphere = vtkSphereSource::New();
    sphere->SetThetaResolution(36.0);
    sphere->SetPhiResolution(18.0);
    sphere->SetRadius(1.0);

  shrink = vtkShrinkPolyData::New();
    shrink->SetShrinkFactor( ShrinkScroll->Position/100.0 );
    shrink->SetInput( sphere->GetOutput() );

  vtkElevationFilter *elev = vtkElevationFilter::New();
    elev->SetInput( shrink->GetOutput() );
    elev->SetLowPoint(-1,-1,-1);
    elev->SetHighPoint( 1, 1, 1);
    elev->SetScalarRange(0,1);

  vtkPolyDataMapper *aMapper = vtkPolyDataMapper::New();
    aMapper->SetInput( elev->GetPolyDataOutput() );
    aMapper->SetScalarRange(0,1);

  vtkActor *anActor = vtkActor::New();
    anActor->SetMapper(aMapper);

  // Use these functions to get the actual RenderWindow/Renderers.
  vtkWindow1->GetRenderer()->AddActor(anActor);

  // We don't need these any more, they are reference counted by the
  // pipeline and we can delete them. They'll be destructed when everything
  // finishes.  We'll keep a pointer to the shrinkfilter so we can use our
  // scroller.

  anActor->Delete();
  aMapper->Delete();
  sphere->Delete();
  elev->Delete();

  vtkWindow1->GetRenderer()->ResetCamera();
  vtkWindow1->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TVTK_Form::ShrinkScrollChange(TObject *Sender)
{
  if (!shrink)
    {
    return;
    }
  shrink->SetShrinkFactor( ShrinkScroll->Position/100.0 );
  vtkWindow1->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TVTK_Form::vtkWindow1Enter(TObject *Sender)
{
  BorderWindow->Color = clMaroon;
}
//---------------------------------------------------------------------------
void __fastcall TVTK_Form::vtkWindow1Exit(TObject *Sender)
{
  BorderWindow->Color = clBtnFace;
}
//---------------------------------------------------------------------------

void __fastcall TVTK_Form::FormShow(TObject *Sender)
{
  // These calls are made to enforce creation of the internal
  // vtk components of the vtkBorlandRenderWindow.  If this were
  // not done, clicking on the component would attempt to pass
  // window messages to non-existent entities.  This behaviour
  // could be changed in future.

  vtkRenderWindowInteractor * iact = vtkWindow1->GetInteractor();
  vtkRenderer* ren1 = vtkWindow1->GetRenderer();
}
//---------------------------------------------------------------------------