PolyMap.cc 4.98 KB
Newer Older
1
2
/*=========================================================================

Ken Martin's avatar
Ken Martin committed
3
  Program:   Visualization Toolkit
4
5
6
7
8
  Module:    PolyMap.cc
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

Ken Martin's avatar
Ken Martin committed
9
This file is part of the Visualization Toolkit. No part of this file or its 
10
11
12
13
14
15
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.

Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994 

=========================================================================*/
Will Schroeder's avatar
Will Schroeder committed
16
#include "PolyMap.hh"
Will Schroeder's avatar
Will Schroeder committed
17

Will Schroeder's avatar
Will Schroeder committed
18
19
20
// Description:
// Construct mapper with vertices, lines, polygons, and triangle strips
// turned on.
Ken Martin's avatar
Ken Martin committed
21
vtkPolyMapper::vtkPolyMapper()
Will Schroeder's avatar
Will Schroeder committed
22
{
Will Schroeder's avatar
Will Schroeder committed
23
24
25
26
  this->Verts = NULL;
  this->Lines = NULL;
  this->Polys = NULL;
  this->Strips = NULL;
Will Schroeder's avatar
Will Schroeder committed
27
28
  this->Colors = NULL;

Will Schroeder's avatar
Will Schroeder committed
29
30
31
32
  this->VertsVisibility = 1;
  this->LinesVisibility = 1;
  this->PolysVisibility = 1;
  this->StripsVisibility = 1;
Will Schroeder's avatar
Will Schroeder committed
33
34
}

Ken Martin's avatar
Ken Martin committed
35
vtkPolyMapper::~vtkPolyMapper()
Will Schroeder's avatar
Will Schroeder committed
36
{
Will Schroeder's avatar
Will Schroeder committed
37
38
39
40
41
42
  //delete internally created objects
  if ( this->Verts != NULL ) delete this->Verts;
  if ( this->Lines != NULL ) delete this->Lines;
  if ( this->Polys != NULL ) delete this->Polys;
  if ( this->Strips != NULL ) delete this->Strips;
  if ( this->Colors != NULL ) delete this->Colors;
Will Schroeder's avatar
Will Schroeder committed
43
44
}

Ken Martin's avatar
Ken Martin committed
45
void vtkPolyMapper::SetInput(vtkPolyData *in)
Will Schroeder's avatar
Will Schroeder committed
46
{
Will Schroeder's avatar
Will Schroeder committed
47
48
  if (in != this->Input )
    {
Ken Martin's avatar
Ken Martin committed
49
50
    vtkDebugMacro(<<" setting Input to " << (void *)in);
    this->Input = (vtkDataSet *) in;
Will Schroeder's avatar
Will Schroeder committed
51
52
    this->Modified();
    }
Will Schroeder's avatar
Will Schroeder committed
53
}
Will Schroeder's avatar
Will Schroeder committed
54

Will Schroeder's avatar
Will Schroeder committed
55
56
57
//
// Return bounding box of data
//
Ken Martin's avatar
Ken Martin committed
58
float *vtkPolyMapper::GetBounds()
Will Schroeder's avatar
Will Schroeder committed
59
60
61
62
63
64
65
66
67
68
69
{
  static float bounds[] = {-1.0,1.0, -1.0,1.0, -1.0,1.0};

  if ( ! this->Input ) 
    return bounds;
  else
    {
    this->Input->Update();
    return this->Input->GetBounds();
    }
}
Ken Martin's avatar
Ken Martin committed
70
71

//
Will Schroeder's avatar
Will Schroeder committed
72
// Receives from Actor -> maps data to primitives
Ken Martin's avatar
Ken Martin committed
73
//
Ken Martin's avatar
Ken Martin committed
74
void vtkPolyMapper::Render(vtkRenderer *ren)
Ken Martin's avatar
Ken Martin committed
75
{
Ken Martin's avatar
Ken Martin committed
76
77
  vtkPointData *pd;
  vtkScalars *scalars;
Will Schroeder's avatar
Will Schroeder committed
78
  int i, numPts;
Ken Martin's avatar
Ken Martin committed
79
80
  vtkPolyData *input=(vtkPolyData *)this->Input;
  vtkColorScalars *colors;
Will Schroeder's avatar
Will Schroeder committed
81
82
83
//
// make sure that we've been properly initialized
//
Will Schroeder's avatar
Will Schroeder committed
84
  if ( input == NULL ) 
Will Schroeder's avatar
Will Schroeder committed
85
    {
Ken Martin's avatar
Ken Martin committed
86
    vtkErrorMacro(<< "No input!");
Will Schroeder's avatar
Will Schroeder committed
87
    return;
Will Schroeder's avatar
Will Schroeder committed
88
    }
Will Schroeder's avatar
Will Schroeder committed
89
  else
Will Schroeder's avatar
Will Schroeder committed
90
    {
Will Schroeder's avatar
Will Schroeder committed
91
    input->Update();
Will Schroeder's avatar
Will Schroeder committed
92
93
    numPts = input->GetNumberOfPoints();
    } 
Will Schroeder's avatar
Will Schroeder committed
94

Will Schroeder's avatar
Will Schroeder committed
95
  if ( this->LookupTable == NULL ) this->CreateDefaultLookupTable();
Will Schroeder's avatar
Will Schroeder committed
96
  this->LookupTable->Build();
Will Schroeder's avatar
Will Schroeder committed
97
//
Will Schroeder's avatar
Will Schroeder committed
98
// Now send data down to primitives and draw it
Will Schroeder's avatar
Will Schroeder committed
99
//
Will Schroeder's avatar
Will Schroeder committed
100
101
  if ( this->GetMTime() > this->BuildTime || 
  input->GetMTime() > this->BuildTime || 
102
  this->LookupTable->GetMTime() > this->BuildTime )
Will Schroeder's avatar
Will Schroeder committed
103
    {
Will Schroeder's avatar
Will Schroeder committed
104
105
106
//
// create colors
//
Will Schroeder's avatar
Will Schroeder committed
107
    if ( this->ScalarsVisible && (pd=input->GetPointData()) && 
Will Schroeder's avatar
Will Schroeder committed
108
109
    (scalars=pd->GetScalars()) )
      {
110
      if ( strcmp(scalars->GetScalarType(),"ColorScalar") )
111
112
113
        {
        if ( this->Colors == NULL ) 
          {
Ken Martin's avatar
Ken Martin committed
114
          this->Colors = colors = (vtkColorScalars *) new vtkAPixmap(numPts);
115
116
117
          }
        else
          {
Will Schroeder's avatar
Will Schroeder committed
118
          int numColors=this->Colors->GetNumberOfColors();
119
          colors = this->Colors;
120
          if ( numColors < numPts ) colors->Allocate(numPts);
121
122
123
          }

        this->LookupTable->SetTableRange(this->ScalarRange);
Will Schroeder's avatar
Will Schroeder committed
124
        for (i=0; i < numPts; i++)
125
126
127
128
          {
          colors->SetColor(i,this->LookupTable->MapValue(scalars->GetScalar(i)));
          }
        }
Will Schroeder's avatar
Will Schroeder committed
129
      else //color scalar
Will Schroeder's avatar
Will Schroeder committed
130
        {
Ken Martin's avatar
Ken Martin committed
131
        colors = (vtkColorScalars *)scalars;
Will Schroeder's avatar
Will Schroeder committed
132
133
134
        }
      }
    else
Will Schroeder's avatar
Will Schroeder committed
135
      {
Will Schroeder's avatar
Will Schroeder committed
136
      if ( this->Colors ) delete this->Colors;
137
      this->Colors = colors = NULL;
Will Schroeder's avatar
Will Schroeder committed
138
      }
Ken Martin's avatar
Ken Martin committed
139

Will Schroeder's avatar
Will Schroeder committed
140
    if (this->VertsVisibility && input->GetNumberOfVerts())
Ken Martin's avatar
Ken Martin committed
141
142
      {
      if (!this->Verts) this->Verts = ren->GetPrimitive("points");
143
      this->Verts->Build(input,colors);
Ken Martin's avatar
Ken Martin committed
144
      }
Will Schroeder's avatar
Will Schroeder committed
145
    if ( this->LinesVisibility && input->GetNumberOfLines())
Ken Martin's avatar
Ken Martin committed
146
147
      {
      if (!this->Lines) this->Lines = ren->GetPrimitive("lines");
148
      this->Lines->Build(input,colors);
Ken Martin's avatar
Ken Martin committed
149
      }
Will Schroeder's avatar
Will Schroeder committed
150
    if ( this->PolysVisibility && input->GetNumberOfPolys())
Ken Martin's avatar
Ken Martin committed
151
152
      {
      if (!this->Polys) this->Polys = ren->GetPrimitive("polygons");
153
      this->Polys->Build(input,colors);
Ken Martin's avatar
Ken Martin committed
154
      }
Will Schroeder's avatar
Will Schroeder committed
155
    if ( this->StripsVisibility && input->GetNumberOfStrips())
Ken Martin's avatar
Ken Martin committed
156
157
      {
      if (!this->Strips) this->Strips = ren->GetPrimitive("triangle_strips");
158
      this->Strips->Build(input,colors);
Ken Martin's avatar
Ken Martin committed
159
160
      }

Will Schroeder's avatar
Will Schroeder committed
161
    this->BuildTime.Modified();
Will Schroeder's avatar
Will Schroeder committed
162
    }
Will Schroeder's avatar
Will Schroeder committed
163

Ken Martin's avatar
Ken Martin committed
164
  // draw the primitives
Will Schroeder's avatar
Will Schroeder committed
165
  if (this->VertsVisibility && input->GetNumberOfVerts())
Ken Martin's avatar
Ken Martin committed
166
167
168
    {
    this->Verts->Draw(ren);
    }
Will Schroeder's avatar
Will Schroeder committed
169
  if ( this->LinesVisibility && input->GetNumberOfLines())
Ken Martin's avatar
Ken Martin committed
170
171
172
    {
    this->Lines->Draw(ren);
    }
Will Schroeder's avatar
Will Schroeder committed
173
  if ( this->PolysVisibility && input->GetNumberOfPolys())
Ken Martin's avatar
Ken Martin committed
174
175
176
    {
    this->Polys->Draw(ren);
    }
Will Schroeder's avatar
Will Schroeder committed
177
  if ( this->StripsVisibility && input->GetNumberOfStrips())
Ken Martin's avatar
Ken Martin committed
178
179
180
    {
    this->Strips->Draw(ren);
    }
Ken Martin's avatar
Ken Martin committed
181
182
183

}

Ken Martin's avatar
Ken Martin committed
184
void vtkPolyMapper::PrintSelf(ostream& os, vtkIndent indent)
Will Schroeder's avatar
Will Schroeder committed
185
{
Ken Martin's avatar
Ken Martin committed
186
  vtkMapper::PrintSelf(os,indent);
Will Schroeder's avatar
Will Schroeder committed
187

188
189
190
191
  os << indent << "Vertex Visibility: " << (this->VertsVisibility ? "On\n" : "Off\n");
  os << indent << "Line Visibility: " << (this->LinesVisibility ? "On\n" : "Off\n");
  os << indent << "Polygon Visibility: " << (this->PolysVisibility ? "On\n" : "Off\n");
  os << indent << "Triangle Strip Visibility: " << (this->StripsVisibility ? "On\n" : "Off\n");
Will Schroeder's avatar
Will Schroeder committed
192
193

}