[vtkusers] Texture Mapping PolyData Broke In VTK 8.0??

Donny Zimmerman zmanvortex at gmail.com
Wed Aug 2 15:43:17 EDT 2017


*The following code works in VTK 7.1 but does not work in VTK 8.0 using the
same PC and compiled with Visual Studio 2015. I have attached the XML .vti
image file and also the .txt file used for the lookup table.*

#include "stdafx.h"

#include "vtkAutoInit.h"
#define vtkRenderingCore_AUTOINIT
3(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingOpenGL2)
#define vtkRenderingVolume_AUTOINIT 1(vtkRenderingVolumeOpenGL2)

#include "vtkXMLImageDataReader.h"
#include "vtkImageData.h"
#include "vtkImageViewer2.h"
#include "vtkLookupTable.h"
#include "vtkRenderer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderWindow.h"
#include "vtkImageResize.h"
#include "vtkImageMapToWindowLevelColors.h"
#include "vtkTransformPolyDataFilter.h"
#include "vtkFloatArray.h"
#include "vtkMath.h"
#include "vtkTriangle.h"
#include "vtkPointData.h"
#include "vtkTexture.h"
#include "vtkTransform.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"

#include <iostream>     // std::cout
#include <sstream>      // std::istringstream
#include <string>       // std::string
#include <math.h>

int main()
{
double imgfact = 2.0;

vtkSmartPointer<vtkLookupTable> lookuptable =
vtkSmartPointer<vtkLookupTable>::New();
lookuptable->GetTable()->Reset();
lookuptable->SetNumberOfColors(256);
lookuptable->SetRange(0, 255.0);

std::ifstream infile;
std::string line;

int ind = 0;
double r = 0, g = 0, b = 0, a = 0;
std::string sind, sr, sg, sb, sa;

infile.open("lutable.txt", ifstream::in);
if (infile.is_open())
{
while (infile.good() && ind < 255)
{
std::getline(infile, line);
std::istringstream is(line);
std::getline(is, sind, ',');
std::getline(is, sr, ',');
std::getline(is, sg, ',');
std::getline(is, sb, ',');
std::getline(is, sa);
ind = std::stoi(sind);
r = std::stod(sr);
g = std::stod(sg);
b = std::stod(sb);
a = std::stod(sa);

lookuptable->SetTableValue(ind, r, g, b, a);

}
infile.close();
}
else
{
cout << "Error opening file";
}

lookuptable->Build();

vtkSmartPointer<vtkXMLImageDataReader> imgdat =
vtkSmartPointer<vtkXMLImageDataReader>::New();
imgdat->SetFileName("testimage.vti");
imgdat->ReleaseDataFlagOn();
imgdat->Update();

int dims[3];
imgdat->GetOutput()->GetDimensions(dims);

int img_res_x = dims[0];
int img_res_y = dims[1];

vtkSmartPointer<vtkImageResize> resize1 =
vtkSmartPointer<vtkImageResize>::New();
resize1->SetInputConnection(imgdat->GetOutputPort());
resize1->SetOutputDimensions(img_res_x / imgfact, img_res_y / imgfact, 1);
resize1->SetResizeMethodToOutputDimensions();
resize1->ReleaseDataFlagOn();

vtkSmartPointer<vtkImageResize> resize2 =
vtkSmartPointer<vtkImageResize>::New();
resize2->SetInputConnection(resize1->GetOutputPort());
resize2->SetOutputDimensions(img_res_x, img_res_y, 1);
resize2->SetResizeMethodToOutputDimensions();
resize2->ReleaseDataFlagOn();

vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkCellArray> triangles =
vtkSmartPointer<vtkCellArray>::New();
vtkSmartPointer<vtkFloatArray> textureCoordinates =
vtkSmartPointer<vtkFloatArray>::New();
textureCoordinates->SetNumberOfComponents(3);
textureCoordinates->SetName("TextureCoordinates");

float xval, yval, x, y, z;

double sinang = sin(vtkMath::RadiansFromDegrees(19.0));
z = sinang * 1000.0;

int ptIdIndex = 0;

for (int rrad = 0; rrad < 360; rrad++)
{
vtkSmartPointer<vtkTriangle> triangle = vtkSmartPointer<vtkTriangle>::New();
triangle->GetPointIds()->SetNumberOfIds(3);

// Point 1
points->InsertNextPoint(1000.0, 1000.0, 0.0);
textureCoordinates->InsertNextTuple3(.5, .5, 0);
triangle->GetPointIds()->SetId(0, ptIdIndex++);

// Point 2
xval = (float)(sin(((float)rrad * vtkMath::Pi()) / 180.0));
yval = (float)(cos(((float)rrad * vtkMath::Pi()) / 180.0));
x = 1000.0 + (1000.0 * xval);
y = 1000.0 + (1000.0 * yval);
points->InsertNextPoint(x, y, z);
textureCoordinates->InsertNextTuple3(x / 2000.0, y / 2000.0, 0);
triangle->GetPointIds()->SetId(1, ptIdIndex++);

// Point 3
xval = (float)(sin(((float)(rrad + 1) * vtkMath::Pi()) / 180.0));
yval = (float)(cos(((float)(rrad + 1) * vtkMath::Pi()) / 180.0));
x = 1000.0 + (1000.0 * xval);
y = 1000.0 + (1000.0 * yval);
points->InsertNextPoint(x, y, z);
textureCoordinates->InsertNextTuple3(x / 2000.0, y / 2000.0, 0);
triangle->GetPointIds()->SetId(2, ptIdIndex++);

triangles->InsertNextCell(triangle);

}

vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
polyData->SetPoints(points);
polyData->SetPolys(triangles);
polyData->GetPointData()->SetTCoords(textureCoordinates);

vtkSmartPointer<vtkTexture> texture = vtkSmartPointer<vtkTexture>::New();
texture->MapColorScalarsThroughLookupTableOn();
texture->SetLookupTable(lookuptable);
texture->InterpolateOff();
texture->SetInputConnection(resize2->GetOutputPort());

vtkSmartPointer<vtkTransformPolyDataFilter> tf =
vtkSmartPointer<vtkTransformPolyDataFilter>::New();
tf->SetInputData(polyData);
double xfmscale = 250.0;

vtkSmartPointer<vtkTransform> pdxfm = vtkSmartPointer<vtkTransform>::New();
pdxfm->Scale(xfmscale, xfmscale, xfmscale);
pdxfm->Translate(-img_res_x / 2, -img_res_y / 2, 0);
tf->SetTransform(pdxfm);

vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(tf->GetOutputPort());
mapper->ScalarVisibilityOff();

vtkSmartPointer<vtkActor> radarActor = vtkSmartPointer<vtkActor>::New();
radarActor->SetMapper(mapper);
radarActor->SetTexture(texture);
radarActor->GetProperty()->LightingOff();
radarActor->GetProperty()->ShadingOff();

vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);

renderer->AddActor(radarActor);

renderWindow->Render();
renderWindowInteractor->Start();

return 0;
}

*In 7.1 I see the texture rendered on the polydata correctly, but in 8.0 I
only see the white shaded polydata. Any idea what may have changed in 8.0
that would prevent this from working.*

*Thanks.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170802/e7a90212/attachment-0001.html>
-------------- next part --------------
0,0,0,0,0
1,0,0,0,0
2,0.8,0.8,0.8,0
3,0.8,0.8,0.8,0
4,0.8,0.8,0.8,0
5,0.8,0.8,0.8,0
6,0.772549019607843,0.772549019607843,0.772549019607843,0
7,0.772549019607843,0.772549019607843,0.772549019607843,0
8,0.772549019607843,0.772549019607843,0.772549019607843,0
9,0.772549019607843,0.772549019607843,0.772549019607843,0
10,0.772549019607843,0.772549019607843,0.772549019607843,0
11,0.745098039215686,0.745098039215686,0.745098039215686,0
12,0.745098039215686,0.745098039215686,0.745098039215686,0
13,0.745098039215686,0.745098039215686,0.745098039215686,0
14,0.745098039215686,0.745098039215686,0.745098039215686,0
15,0.745098039215686,0.745098039215686,0.745098039215686,0
16,0.717647058823529,0.717647058823529,0.717647058823529,0
17,0.717647058823529,0.717647058823529,0.717647058823529,0
18,0.717647058823529,0.717647058823529,0.717647058823529,0
19,0.717647058823529,0.717647058823529,0.717647058823529,0
20,0.717647058823529,0.717647058823529,0.717647058823529,0
21,0.690196078431373,0.690196078431373,0.690196078431373,1
22,0.690196078431373,0.690196078431373,0.690196078431373,1
23,0.690196078431373,0.690196078431373,0.690196078431373,1
24,0.690196078431373,0.690196078431373,0.690196078431373,1
25,0.690196078431373,0.690196078431373,0.690196078431373,1
26,0.662745098039216,0.662745098039216,0.662745098039216,1
27,0.662745098039216,0.662745098039216,0.662745098039216,1
28,0.662745098039216,0.662745098039216,0.662745098039216,1
29,0.662745098039216,0.662745098039216,0.662745098039216,1
30,0.662745098039216,0.662745098039216,0.662745098039216,1
31,0.635294117647059,0.635294117647059,0.635294117647059,1
32,0.635294117647059,0.635294117647059,0.635294117647059,1
33,0.635294117647059,0.635294117647059,0.635294117647059,1
34,0.635294117647059,0.635294117647059,0.635294117647059,1
35,0.635294117647059,0.635294117647059,0.635294117647059,1
36,0.607843137254902,0.607843137254902,0.607843137254902,1
37,0.607843137254902,0.607843137254902,0.607843137254902,1
38,0.607843137254902,0.607843137254902,0.607843137254902,1
39,0.607843137254902,0.607843137254902,0.607843137254902,1
40,0.607843137254902,0.607843137254902,0.607843137254902,1
41,0.580392156862745,0.580392156862745,0.580392156862745,1
42,0.580392156862745,0.580392156862745,0.580392156862745,1
43,0.580392156862745,0.580392156862745,0.580392156862745,1
44,0.580392156862745,0.580392156862745,0.580392156862745,1
45,0.580392156862745,0.580392156862745,0.580392156862745,1
46,0.552941176470588,0.552941176470588,0.552941176470588,1
47,0.552941176470588,0.552941176470588,0.552941176470588,1
48,0.552941176470588,0.552941176470588,0.552941176470588,1
49,0.552941176470588,0.552941176470588,0.552941176470588,1
50,0.552941176470588,0.552941176470588,0.552941176470588,1
51,0.525490196078431,0.525490196078431,0.525490196078431,1
52,0.525490196078431,0.525490196078431,0.525490196078431,1
53,0.525490196078431,0.525490196078431,0.525490196078431,1
54,0.525490196078431,0.525490196078431,0.525490196078431,1
55,0.525490196078431,0.525490196078431,0.525490196078431,1
56,0.498039215686275,0.498039215686275,0.498039215686275,1
57,0.498039215686275,0.498039215686275,0.498039215686275,1
58,0.498039215686275,0.498039215686275,0.498039215686275,1
59,0.498039215686275,0.498039215686275,0.498039215686275,1
60,0.498039215686275,0.498039215686275,0.498039215686275,1
61,0.470588235294118,0.470588235294118,0.470588235294118,1
62,0.470588235294118,0.470588235294118,0.470588235294118,1
63,0.470588235294118,0.470588235294118,0.470588235294118,1
64,0.470588235294118,0.470588235294118,0.470588235294118,1
65,0.470588235294118,0.470588235294118,0.470588235294118,1
66,0.443137254901961,0.443137254901961,0.443137254901961,1
67,0.443137254901961,0.443137254901961,0.443137254901961,1
68,0.443137254901961,0.443137254901961,0.443137254901961,1
69,0.443137254901961,0.443137254901961,0.443137254901961,1
70,0.443137254901961,0.443137254901961,0.443137254901961,1
71,0.376470588235294,0.376470588235294,0.376470588235294,1
72,0.376470588235294,0.376470588235294,0.376470588235294,1
73,0.376470588235294,0.376470588235294,0.376470588235294,1
74,0.376470588235294,0.376470588235294,0.376470588235294,1
75,0.376470588235294,0.376470588235294,0.376470588235294,1
76,0.125490196078431,0.376470588235294,0.501960784313725,1
77,0.125490196078431,0.376470588235294,0.501960784313725,1
78,0.129411764705882,0.407843137254902,0.537254901960784,1
79,0.129411764705882,0.407843137254902,0.537254901960784,1
80,0.133333333333333,0.43921568627451,0.572549019607843,1
81,0.133333333333333,0.43921568627451,0.572549019607843,1
82,0.137254901960784,0.470588235294118,0.607843137254902,1
83,0.137254901960784,0.470588235294118,0.607843137254902,1
84,0.145098039215686,0.501960784313725,0.643137254901961,1
85,0.145098039215686,0.501960784313725,0.643137254901961,1
86,0.149019607843137,0.533333333333333,0.682352941176471,1
87,0.149019607843137,0.533333333333333,0.682352941176471,1
88,0.152941176470588,0.564705882352941,0.717647058823529,1
89,0.152941176470588,0.564705882352941,0.717647058823529,1
90,0.156862745098039,0.596078431372549,0.752941176470588,1
91,0.156862745098039,0.596078431372549,0.752941176470588,1
92,0.16078431372549,0.627450980392157,0.788235294117647,1
93,0.16078431372549,0.627450980392157,0.788235294117647,1
94,0.168627450980392,0.658823529411765,0.823529411764706,1
95,0.168627450980392,0.658823529411765,0.823529411764706,1
96,0.172549019607843,0.690196078431373,0.858823529411765,1
97,0.172549019607843,0.690196078431373,0.858823529411765,1
98,0.176470588235294,0.72156862745098,0.894117647058824,1
99,0.176470588235294,0.72156862745098,0.894117647058824,1
100,0.180392156862745,0.752941176470588,0.929411764705882,1
101,0.180392156862745,0.752941176470588,0.929411764705882,1
102,0.184313725490196,0.784313725490196,0.964705882352941,1
103,0.184313725490196,0.784313725490196,0.964705882352941,1
104,0.188235294117647,0.815686274509804,1,1
105,0.188235294117647,0.815686274509804,1,1
106,0,1,0,1
107,0,1,0,1
108,0,0.964705882352941,0,1
109,0,0.964705882352941,0,1
110,0,0.925490196078431,0,1
111,0,0.925490196078431,0,1
112,0,0.890196078431373,0,1
113,0,0.890196078431373,0,1
114,0,0.850980392156863,0,1
115,0,0.850980392156863,0,1
116,0,0.815686274509804,0,1
117,0,0.815686274509804,0,1
118,0,0.776470588235294,0,1
119,0,0.776470588235294,0,1
120,0,0.741176470588235,0,1
121,0,0.741176470588235,0,1
122,0,0.705882352941177,0,1
123,0,0.705882352941177,0,1
124,0,0.666666666666667,0,1
125,0,0.666666666666667,0,1
126,0,0.631372549019608,0,1
127,0,0.631372549019608,0,1
128,0,0.592156862745098,0,1
129,0,0.592156862745098,0,1
130,0,0.556862745098039,0,1
131,0,0.556862745098039,0,1
132,0,0.52156862745098,0,1
133,0,0.52156862745098,0,1
134,0,0.482352941176471,0,1
135,0,0.482352941176471,0,1
136,0,0.447058823529412,0,1
137,0,0.447058823529412,0,1
138,0,0.407843137254902,0,1
139,0,0.407843137254902,0,1
140,0,0.372549019607843,0,1
141,0,0.372549019607843,0,1
142,0,0.333333333333333,0,1
143,0,0.333333333333333,0,1
144,0,0.298039215686275,0,1
145,0,0.298039215686275,0,1
146,1,0.901960784313726,0,1
147,1,0.901960784313726,0,1
148,1,0.858823529411765,0,1
149,1,0.858823529411765,0,1
150,1,0.811764705882353,0,1
151,1,0.811764705882353,0,1
152,1,0.768627450980392,0,1
153,1,0.768627450980392,0,1
154,1,0.725490196078431,0,1
155,1,0.725490196078431,0,1
156,1,0.67843137254902,0,1
157,1,0.67843137254902,0,1
158,1,0.635294117647059,0,1
159,1,0.635294117647059,0,1
160,1,0.592156862745098,0,1
161,1,0.592156862745098,0,1
162,1,0.545098039215686,0,1
163,1,0.545098039215686,0,1
164,1,0.501960784313725,0,1
165,1,0.501960784313725,0,1
166,1,0,0,1
167,1,0,0,1
168,0.929411764705882,0,0,1
169,0.929411764705882,0,0,1
170,0.862745098039216,0,0,1
171,0.862745098039216,0,0,1
172,0.792156862745098,0,0,1
173,0.792156862745098,0,0,1
174,0.72156862745098,0,0,1
175,0.72156862745098,0,0,1
176,0.654901960784314,0,0,1
177,0.654901960784314,0,0,1
178,0.584313725490196,0,0,1
179,0.584313725490196,0,0,1
180,0.513725490196078,0,0,1
181,0.513725490196078,0,0,1
182,0.447058823529412,0,0,1
183,0.447058823529412,0,0,1
184,0.376470588235294,0,0,1
185,0.376470588235294,0,0,1
186,1,1,1,1
187,1,1,1,1
188,1,1,1,1
189,1,1,1,1
190,1,1,1,1
191,1,1,1,1
192,1,1,1,1
193,1,1,1,1
194,1,1,1,1
195,1,1,1,1
196,0.564705882352941,0.188235294117647,0.815686274509804,1
197,0.564705882352941,0.188235294117647,0.815686274509804,1
198,0.564705882352941,0.188235294117647,0.815686274509804,1
199,0.564705882352941,0.188235294117647,0.815686274509804,1
200,0.564705882352941,0.188235294117647,0.815686274509804,1
201,0.564705882352941,0.188235294117647,0.815686274509804,1
202,0.564705882352941,0.188235294117647,0.815686274509804,1
203,0.564705882352941,0.188235294117647,0.815686274509804,1
204,0.564705882352941,0.188235294117647,0.815686274509804,1
205,0.564705882352941,0.188235294117647,0.815686274509804,1
206,1,0.125490196078431,1,1
207,1,0.125490196078431,1,1
208,1,0.125490196078431,1,1
209,1,0.125490196078431,1,1
210,1,0.125490196078431,1,1
211,1,0.125490196078431,1,1
212,1,0.125490196078431,1,1
213,1,0.125490196078431,1,1
214,1,0.125490196078431,1,1
215,1,0.125490196078431,1,1
216,1,0,0.501960784313725,1
217,1,0,0.501960784313725,1
218,1,0,0.501960784313725,1
219,1,0,0.501960784313725,1
220,1,0,0.501960784313725,1
221,1,0,0.501960784313725,1
222,1,0,0.501960784313725,1
223,1,0,0.501960784313725,1
224,1,0,0.501960784313725,1
225,1,0,0.501960784313725,1
226,0.882352941176471,0.490196078431373,0.588235294117647,1
227,0.882352941176471,0.490196078431373,0.588235294117647,1
228,0.882352941176471,0.490196078431373,0.588235294117647,1
229,0.882352941176471,0.490196078431373,0.588235294117647,1
230,0.882352941176471,0.490196078431373,0.588235294117647,1
231,0.882352941176471,0.490196078431373,0.588235294117647,1
232,0.882352941176471,0.490196078431373,0.588235294117647,1
233,0.882352941176471,0.490196078431373,0.588235294117647,1
234,0.882352941176471,0.490196078431373,0.588235294117647,1
235,0.882352941176471,0.490196078431373,0.588235294117647,1
236,0.882352941176471,0.490196078431373,0.588235294117647,1
237,0.882352941176471,0.490196078431373,0.588235294117647,1
238,0.882352941176471,0.490196078431373,0.588235294117647,1
239,0.882352941176471,0.490196078431373,0.588235294117647,1
240,0.882352941176471,0.490196078431373,0.588235294117647,1
241,0.882352941176471,0.490196078431373,0.588235294117647,1
242,0.882352941176471,0.490196078431373,0.588235294117647,1
243,0.882352941176471,0.490196078431373,0.588235294117647,1
244,0.882352941176471,0.490196078431373,0.588235294117647,1
245,0.882352941176471,0.490196078431373,0.588235294117647,1
246,0.882352941176471,0.490196078431373,0.588235294117647,1
247,0.882352941176471,0.490196078431373,0.588235294117647,1
248,0.882352941176471,0.490196078431373,0.588235294117647,1
249,0.882352941176471,0.490196078431373,0.588235294117647,1
250,0.882352941176471,0.490196078431373,0.588235294117647,1
251,0.882352941176471,0.490196078431373,0.588235294117647,1
252,0.882352941176471,0.490196078431373,0.588235294117647,1
253,0.882352941176471,0.490196078431373,0.588235294117647,1
254,0.882352941176471,0.490196078431373,0.588235294117647,1
255,0.882352941176471,0.490196078431373,0.588235294117647,1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testimage.vti
Type: application/octet-stream
Size: 474540 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170802/e7a90212/attachment-0001.obj>


More information about the vtkusers mailing list