1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    otherColorTransferFunction.cxx
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
16 // .NAME
17 // .SECTION Description
18 // this program tests the ColorTransferFunction
19 
20 #include "vtkColorTransferFunction.h"
21 #include "vtkDebugLeaks.h"
22 
23 #include <sstream>
24 
Test(ostream & strm)25 int Test(ostream& strm)
26 {
27   int i, j, k;
28   vtkColorTransferFunction *ctf1 = vtkColorTransferFunction::New();
29 
30   // actual test
31   strm << "Test vtkColorTransferFunction Start" << endl;
32 
33   ctf1->AddRGBPoint (0.0, 1, 0, 0);
34   ctf1->AddHSVPoint (1.0, 1, 1, .6);
35   ctf1->AddRGBSegment (2.0, 1, 1, 1, 10.0, 0, 0, 0);
36   ctf1->AddHSVSegment (11.0, 1, 1, .6, 15.0, .1, .2, .3);
37   strm << *ctf1;
38 
39   double rgb[3];
40   ctf1->GetColor(.5, rgb);
41   strm << "GetColor(.5) = "
42     << rgb[0] << ", " << rgb[1] << ", " << rgb[2] << endl;
43 
44   strm << "GetRedValue(.5) = " << ctf1->GetRedValue(.5) << endl;
45   strm << "GetGreenValue(.5) = " << ctf1->GetGreenValue(.5) << endl;
46   strm << "GetBlueValue(.5) = " << ctf1->GetBlueValue(.5) << endl;
47 
48   strm << "MapValue(12) = "
49        << (int) ctf1->MapValue(12)[0] << ", "
50        << (int) ctf1->MapValue(12)[1] << ", "
51        << (int) ctf1->MapValue(12)[2] << endl;
52 
53   strm << "GetRange = "
54        << ctf1->GetRange()[0] << ","
55        << ctf1->GetRange()[1] << endl;
56 
57   double table[3][256];
58 
59   ctf1->GetTable(0, 15, 256, &table[0][0]);
60   strm << "GetTable(0, 15, 256, &table[0][0])" << endl;
61   for (i = 0; i < 256; i++)
62   {
63       for (j = 0; j < 3; j++)
64       {
65         strm << table[j][i] << " ";
66       }
67       strm << endl;
68   }
69 
70   strm << "BuildFunctionFrom(0, 15, 256, &table[0][0])" << endl;
71   vtkColorTransferFunction *ctf2 = vtkColorTransferFunction::New();
72   ctf2->BuildFunctionFromTable(0, 15, 256, &table[0][0]);
73 
74   ctf2->SetColorSpaceToRGB();
75   ctf2->GetTable(0,15,512);
76 
77   ctf2->SetColorSpaceToHSV();
78   ctf2->GetTable(0,15,512);
79 
80   ctf1->DeepCopy(ctf2);
81   strm << "ctf1->DeepCopy(ctf2)" << endl;
82   strm << *ctf1;
83 
84   ctf1->RemovePoint (10);
85   strm << *ctf1;
86 
87   ctf1->RemoveAllPoints();
88   strm << *ctf1;
89 
90   char *cData = new char[128];
91   unsigned char *ucData = new unsigned char[128];
92   short *sData = new short[128];
93   unsigned short *usData = new unsigned short[128];
94   int *iData = new int[128];
95   unsigned int *uiData = new unsigned int[128];
96   long *lData = new long[128];
97   unsigned long *ulData = new unsigned long[128];
98   float *fData = new float[128];
99   double *dData = new double[128];
100 
101   for (k = 0; k < 128; k++)
102   {
103     *(cData+k) = static_cast<char>(static_cast<float>(k)/255.0);
104     *(ucData+k) = static_cast<unsigned char>(static_cast<float>(k)/255.0);
105     *(sData+k) = static_cast<short>(static_cast<float>(k)/255.0);
106     *(usData+k) = static_cast<unsigned short>(static_cast<float>(k)/255.0);
107     *(iData+k) = static_cast<int>(static_cast<float>(k)/255.0);
108     *(uiData+k) = static_cast<unsigned int>(static_cast<float>(k)/255.0);
109     *(lData+k) = static_cast<long>(static_cast<float>(k)/255.0);
110     *(ulData+k) = static_cast<unsigned long>(static_cast<float>(k)/255.0);
111     *(fData+k) = static_cast<float>(static_cast<float>(k)/255.0);
112     *(dData+k) = static_cast<double>(static_cast<float>(k)/255.0);
113   }
114 
115   unsigned char *ucResult = new unsigned char[128*4];
116   for (k = 1; k <= 4; k++)
117   {
118     ctf2->MapScalarsThroughTable2((void *) cData, ucResult, VTK_CHAR, 128, 1, k);
119     ctf2->MapScalarsThroughTable2((void *) ucData, ucResult, VTK_UNSIGNED_CHAR, 128, 1, k);
120     ctf2->MapScalarsThroughTable2((void *) sData, ucResult, VTK_SHORT, 128, 1, k);
121     ctf2->MapScalarsThroughTable2((void *) usData, ucResult, VTK_UNSIGNED_SHORT, 128, 1, k);
122     ctf2->MapScalarsThroughTable2((void *) iData, ucResult, VTK_INT, 128, 1, k);
123     ctf2->MapScalarsThroughTable2((void *) uiData, ucResult, VTK_UNSIGNED_INT, 128, 1, k);
124     ctf2->MapScalarsThroughTable2((void *) lData, ucResult, VTK_LONG, 128, 1, k);
125     ctf2->MapScalarsThroughTable2((void *) ulData, ucResult, VTK_UNSIGNED_LONG, 128, 1, k);
126     ctf2->MapScalarsThroughTable2((void *) fData, ucResult, VTK_FLOAT, 128, 1, k);
127     ctf2->MapScalarsThroughTable2((void *) dData, ucResult, VTK_DOUBLE, 128, 1, k);
128   }
129 
130   ctf1->Delete();
131   ctf2->Delete();
132 
133   delete []ucResult;
134   delete []cData;
135   delete []ucData;
136   delete []sData;
137   delete []usData;
138   delete []iData;
139   delete []uiData;
140   delete []lData;
141   delete []ulData;
142   delete []fData;
143   delete []dData;
144 
145   strm << "Test vtkColorTransferFunction End" << endl;
146   return 0;
147 }
148 
149 
otherColorTransferFunction(int,char * [])150 int otherColorTransferFunction(int, char *[])
151 {
152   std::ostringstream vtkmsg_with_warning_C4701;
153   return Test(vtkmsg_with_warning_C4701);
154 }
155