File: vtkSDIDoc.cpp

package info (click to toggle)
vtk 5.8.0-17.5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 130,804 kB
  • ctags: 169,145
  • sloc: cpp: 1,129,307; ansic: 708,203; tcl: 48,526; python: 20,878; xml: 6,779; yacc: 4,208; perl: 3,121; java: 2,773; lex: 931; sh: 660; asm: 471; makefile: 301
file content (184 lines) | stat: -rw-r--r-- 3,902 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
// vtkSDIDoc.cpp : implementation of the CvtkSDIDoc class
//

#include "stdafx.h"
#include "vtkSDI.h"

#include "vtkSDIDoc.h"
#include "vtkSDIView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CvtkSDIDoc

IMPLEMENT_DYNCREATE(CvtkSDIDoc, CDocument)

BEGIN_MESSAGE_MAP(CvtkSDIDoc, CDocument)
END_MESSAGE_MAP()


// CvtkSDIDoc construction/destruction

CvtkSDIDoc::CvtkSDIDoc()
{
  this->pvtkDataSetReader  = NULL;

  // Create the the objects used to form the visualisation.
  this->pvtkDataSetMapper  = vtkDataSetMapper::New();
  this->pvtkActor      = vtkActor::New();
  this->pvtkActor2D    = vtkActor2D::New();
  this->pvtkTextMapper  = vtkTextMapper::New();
}

CvtkSDIDoc::~CvtkSDIDoc()
{
}

BOOL CvtkSDIDoc::OnNewDocument()
{
  if (!CDocument::OnNewDocument())
    return FALSE;

  // remove old actors
  RemoveActors();

  // execute object pipeline
  ExecutePipeline();

  return TRUE;
}




// CvtkSDIDoc serialization

void CvtkSDIDoc::Serialize(CArchive& ar)
{
  if (ar.IsStoring())
  {
    // TODO: add storing code here
  }
  else
  {
    // TODO: add loading code here
  }
}


// CvtkSDIDoc diagnostics

#ifdef _DEBUG
void CvtkSDIDoc::AssertValid() const
{
  CDocument::AssertValid();
}

void CvtkSDIDoc::Dump(CDumpContext& dc) const
{
  CDocument::Dump(dc);
}
#endif //_DEBUG


// CvtkSDIDoc commands

void CvtkSDIDoc::RemoveActors()
{
  // get our renderer first
  POSITION pos = this->GetFirstViewPosition();
  CvtkSDIView *pcvtkSDIView = NULL;

  if (pos)
  {
    pcvtkSDIView = (CvtkSDIView *)GetNextView(pos);
  }
  else  // return
  {
    ASSERT(FALSE);
    return;
  }

  // remove old actors
  pcvtkSDIView->GetRenderer()->RemoveActor(this->pvtkActor);
  pcvtkSDIView->GetRenderer()->RemoveActor(this->pvtkActor2D);
}

BOOL CvtkSDIDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
  if (!CDocument::OnOpenDocument(lpszPathName))
    return FALSE;

  // remove old actors
  RemoveActors();

  // create new data reader
  this->pvtkDataSetReader = vtkDataSetReader::New();
  this->pvtkDataSetReader->SetFileName(lpszPathName);

  // execute object pipeline
  ExecutePipeline();

  return TRUE;
}

void CvtkSDIDoc::OnCloseDocument()
{
  // delete data
  if (this->pvtkDataSetReader)  this->pvtkDataSetReader->Delete();

  // Delete the the objects used to form the visualisation.
  if (this->pvtkDataSetMapper)  this->pvtkDataSetMapper->Delete();
  if (this->pvtkActor)      this->pvtkActor->Delete();
  if (this->pvtkActor2D)      this->pvtkActor2D->Delete();
  if (this->pvtkTextMapper)    this->pvtkTextMapper->Delete();

  CDocument::OnCloseDocument();
}

void CvtkSDIDoc::ExecutePipeline()
{
  // get our renderer first
  POSITION pos = this->GetFirstViewPosition();
  CvtkSDIView *pcvtkSDIView = NULL;

  if (pos)
  {
    pcvtkSDIView = (CvtkSDIView *)GetNextView(pos);
  }
  else  // return
  {
    ASSERT(FALSE);
    return;
  }

  if (pvtkDataSetReader)  // have file
  {
    this->pvtkDataSetMapper->SetInput(this->pvtkDataSetReader->GetOutput());
    this->pvtkActor->SetMapper(this->pvtkDataSetMapper);

    this->pvtkTextMapper->SetInput(this->pvtkDataSetReader->GetFileName());
    this->pvtkTextMapper->GetTextProperty()->SetFontSize(12);
    this->pvtkActor2D->SetMapper(this->pvtkTextMapper);

    pcvtkSDIView->GetRenderer()->SetBackground(0.0,0.0,0.4);
    pcvtkSDIView->GetRenderer()->AddActor(this->pvtkActor);
    pcvtkSDIView->GetRenderer()->AddActor(this->pvtkActor2D);
    pcvtkSDIView->GetRenderer()->ResetCamera();
    pvtkDataSetReader->Delete();
    pvtkDataSetReader = NULL;
  }
  else  // have no file
  {
    this->pvtkTextMapper->SetInput("Hello World");
    this->pvtkTextMapper->GetTextProperty()->SetFontSize(24);
    this->pvtkActor2D->SetMapper(this->pvtkTextMapper);

    pcvtkSDIView->GetRenderer()->SetBackground(0.0,0.0,0.4);
    pcvtkSDIView->GetRenderer()->AddActor(this->pvtkActor2D);
    pcvtkSDIView->GetRenderer()->ResetCamera();
  }
}