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 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
|
using Kitware.VTK;
using System;
// input file is C:\VTK\Rendering\Testing\Tcl\labeledContours.tcl
// output file is AVlabeledContours.cs
/// <summary>
/// The testing class derived from AVlabeledContours
/// </summary>
public class AVlabeledContoursClass
{
/// <summary>
/// The main entry method called by the CSharp driver
/// </summary>
/// <param name="argv"></param>
public static void AVlabeledContours(String [] argv)
{
//Prefix Content is: ""
// demonstrate labeling of contour with scalar value[]
// Create the RenderWindow, Renderer and both Actors[]
//[]
ren1 = vtkRenderer.New();
renWin = vtkRenderWindow.New();
renWin.AddRenderer((vtkRenderer)ren1);
iren = new vtkRenderWindowInteractor();
iren.SetRenderWindow((vtkRenderWindow)renWin);
// Read a slice and contour it[]
v16 = new vtkVolume16Reader();
v16.SetDataDimensions((int)64,(int)64);
v16.GetOutput().SetOrigin((double)0.0,(double)0.0,(double)0.0);
v16.SetDataByteOrderToLittleEndian();
v16.SetFilePrefix((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/headsq/quarter");
v16.SetImageRange((int)45,(int)45);
v16.SetDataSpacing((double)3.2,(double)3.2,(double)1.5);
iso = new vtkContourFilter();
iso.SetInputConnection((vtkAlgorithmOutput)v16.GetOutputPort());
iso.GenerateValues((int)6,(double)500,(double)1150);
iso.Update();
numPts = iso.GetOutput().GetNumberOfPoints();
isoMapper = vtkPolyDataMapper.New();
isoMapper.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort());
isoMapper.ScalarVisibilityOn();
isoMapper.SetScalarRange((double)((vtkDataSet)iso.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)iso.GetOutput()).GetScalarRange()[1]);
isoActor = new vtkActor();
isoActor.SetMapper((vtkMapper)isoMapper);
// Subsample the points and label them[]
mask = new vtkMaskPoints();
mask.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort());
mask.SetOnRatio((int)(numPts/50));
mask.SetMaximumNumberOfPoints((int)50);
mask.RandomModeOn();
// Create labels for points - only show visible points[]
visPts = new vtkSelectVisiblePoints();
visPts.SetInputConnection((vtkAlgorithmOutput)mask.GetOutputPort());
visPts.SetRenderer((vtkRenderer)ren1);
ldm = new vtkLabeledDataMapper();
ldm.SetInputConnection((vtkAlgorithmOutput)mask.GetOutputPort());
// ldm SetLabelFormat "%g"[]
ldm.SetLabelModeToLabelScalars();
tprop = ldm.GetLabelTextProperty();
tprop.SetFontFamilyToArial();
tprop.SetFontSize((int)10);
tprop.SetColor((double)1,(double)0,(double)0);
contourLabels = new vtkActor2D();
contourLabels.SetMapper((vtkMapper2D)ldm);
// Add the actors to the renderer, set the background and size[]
//[]
ren1.AddActor2D((vtkProp)isoActor);
ren1.AddActor2D((vtkProp)contourLabels);
ren1.SetBackground((double)1,(double)1,(double)1);
renWin.SetSize((int)500,(int)500);
renWin.Render();
ren1.GetActiveCamera().Zoom((double)1.5);
// render the image[]
//[]
// prevent the tk window from showing up then start the event loop[]
//deleteAllVTKObjects();
}
static string VTK_DATA_ROOT;
static int threshold;
static vtkRenderer ren1;
static vtkRenderWindow renWin;
static vtkRenderWindowInteractor iren;
static vtkVolume16Reader v16;
static vtkContourFilter iso;
static long numPts;
static vtkPolyDataMapper isoMapper;
static vtkActor isoActor;
static vtkMaskPoints mask;
static vtkSelectVisiblePoints visPts;
static vtkLabeledDataMapper ldm;
static vtkTextProperty tprop;
static vtkActor2D contourLabels;
///<summary> A Get Method for Static Variables </summary>
public static string GetVTK_DATA_ROOT()
{
return VTK_DATA_ROOT;
}
///<summary> A Set Method for Static Variables </summary>
public static void SetVTK_DATA_ROOT(string toSet)
{
VTK_DATA_ROOT = toSet;
}
///<summary> A Get Method for Static Variables </summary>
public static int Getthreshold()
{
return threshold;
}
///<summary> A Set Method for Static Variables </summary>
public static void Setthreshold(int toSet)
{
threshold = toSet;
}
///<summary> A Get Method for Static Variables </summary>
public static vtkRenderer Getren1()
{
return ren1;
}
///<summary> A Set Method for Static Variables </summary>
public static void Setren1(vtkRenderer toSet)
{
ren1 = toSet;
}
///<summary> A Get Method for Static Variables </summary>
public static vtkRenderWindow GetrenWin()
{
return renWin;
}
///<summary> A Set Method for Static Variables </summary>
public static void SetrenWin(vtkRenderWindow toSet)
{
renWin = toSet;
}
///<summary> A Get Method for Static Variables </summary>
public static vtkRenderWindowInteractor Getiren()
{
return iren;
}
///<summary> A Set Method for Static Variables </summary>
public static void Setiren(vtkRenderWindowInteractor toSet)
{
iren = toSet;
}
///<summary> A Get Method for Static Variables </summary>
public static vtkVolume16Reader Getv16()
{
return v16;
}
///<summary> A Set Method for Static Variables </summary>
public static void Setv16(vtkVolume16Reader toSet)
{
v16 = toSet;
}
///<summary> A Get Method for Static Variables </summary>
public static vtkContourFilter Getiso()
{
return iso;
}
///<summary> A Set Method for Static Variables </summary>
public static void Setiso(vtkContourFilter toSet)
{
iso = toSet;
}
///<summary> A Get Method for Static Variables </summary>
public static long GetnumPts()
{
return numPts;
}
///<summary> A Set Method for Static Variables </summary>
public static void SetnumPts(long toSet)
{
numPts = toSet;
}
///<summary> A Get Method for Static Variables </summary>
public static vtkPolyDataMapper GetisoMapper()
{
return isoMapper;
}
///<summary> A Set Method for Static Variables </summary>
public static void SetisoMapper(vtkPolyDataMapper toSet)
{
isoMapper = toSet;
}
///<summary> A Get Method for Static Variables </summary>
public static vtkActor GetisoActor()
{
return isoActor;
}
///<summary> A Set Method for Static Variables </summary>
public static void SetisoActor(vtkActor toSet)
{
isoActor = toSet;
}
///<summary> A Get Method for Static Variables </summary>
public static vtkMaskPoints Getmask()
{
return mask;
}
///<summary> A Set Method for Static Variables </summary>
public static void Setmask(vtkMaskPoints toSet)
{
mask = toSet;
}
///<summary> A Get Method for Static Variables </summary>
public static vtkSelectVisiblePoints GetvisPts()
{
return visPts;
}
///<summary> A Set Method for Static Variables </summary>
public static void SetvisPts(vtkSelectVisiblePoints toSet)
{
visPts = toSet;
}
///<summary> A Get Method for Static Variables </summary>
public static vtkLabeledDataMapper Getldm()
{
return ldm;
}
///<summary> A Set Method for Static Variables </summary>
public static void Setldm(vtkLabeledDataMapper toSet)
{
ldm = toSet;
}
///<summary> A Get Method for Static Variables </summary>
public static vtkTextProperty Gettprop()
{
return tprop;
}
///<summary> A Set Method for Static Variables </summary>
public static void Settprop(vtkTextProperty toSet)
{
tprop = toSet;
}
///<summary> A Get Method for Static Variables </summary>
public static vtkActor2D GetcontourLabels()
{
return contourLabels;
}
///<summary> A Set Method for Static Variables </summary>
public static void SetcontourLabels(vtkActor2D toSet)
{
contourLabels = toSet;
}
///<summary>Deletes all static objects created</summary>
public static void deleteAllVTKObjects()
{
//clean up vtk objects
if(ren1!= null){ren1.Dispose();}
if(renWin!= null){renWin.Dispose();}
if(iren!= null){iren.Dispose();}
if(v16!= null){v16.Dispose();}
if(iso!= null){iso.Dispose();}
if(isoMapper!= null){isoMapper.Dispose();}
if(isoActor!= null){isoActor.Dispose();}
if(mask!= null){mask.Dispose();}
if(visPts!= null){visPts.Dispose();}
if(ldm!= null){ldm.Dispose();}
if(tprop!= null){tprop.Dispose();}
if(contourLabels!= null){contourLabels.Dispose();}
}
}
//--- end of script --//
|