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 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
|
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkImageOpenClose3D.cxx,v $
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkImageOpenClose3D.h"
#include "vtkGarbageCollector.h"
#include "vtkImageData.h"
#include "vtkImageDilateErode3D.h"
#include "vtkObjectFactory.h"
#include "vtkCommand.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkExecutive.h"
#include <math.h>
vtkCxxRevisionMacro(vtkImageOpenClose3D, "$Revision: 1.30.4.2 $");
vtkStandardNewMacro(vtkImageOpenClose3D);
//----------------------------------------------------------------------------
// functions to convert progress calls.
class vtkImageOpenClose3DProgress : public vtkCommand
{
public:
// generic new method
static vtkImageOpenClose3DProgress *New()
{ return new vtkImageOpenClose3DProgress; }
// the execute
virtual void Execute(vtkObject *caller,
unsigned long event, void* vtkNotUsed(v))
{
vtkAlgorithm *alg = vtkAlgorithm::SafeDownCast(caller);
if (event == vtkCommand::ProgressEvent && alg)
{
this->Self->UpdateProgress(this->Offset + 0.5 *
alg->GetProgress());
}
}
// some ivars that should be set
vtkImageOpenClose3D *Self;
double Offset;
};
//----------------------------------------------------------------------------
vtkImageOpenClose3D::vtkImageOpenClose3D()
{
// create the filter chain
this->Filter0 = vtkImageDilateErode3D::New();
vtkImageOpenClose3DProgress *cb = vtkImageOpenClose3DProgress::New();
cb->Self = this;
cb->Offset = 0;
this->Filter0->AddObserver(vtkCommand::ProgressEvent, cb);
cb->Delete();
this->Filter1 = vtkImageDilateErode3D::New();
cb = vtkImageOpenClose3DProgress::New();
cb->Self = this;
cb->Offset = 0.5;
this->Filter1->AddObserver(vtkCommand::ProgressEvent, cb);
cb->Delete();
this->SetOpenValue(0.0);
this->SetCloseValue(255.0);
// connect up the internal pipeline
this->Filter1->SetInputConnection(this->Filter0->GetOutputPort());
}
//----------------------------------------------------------------------------
// Destructor: Delete the sub filters.
vtkImageOpenClose3D::~vtkImageOpenClose3D()
{
if (this->Filter0)
{
this->Filter0->Delete();
}
if (this->Filter1)
{
this->Filter1->Delete();
}
}
//----------------------------------------------------------------------------
void vtkImageOpenClose3D::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Filter0: \n";
this->Filter0->PrintSelf(os, indent.GetNextIndent());
os << indent << "Filter1: \n";
this->Filter1->PrintSelf(os, indent.GetNextIndent());
}
//----------------------------------------------------------------------------
// Turn debugging output on. (in sub filters also)
void vtkImageOpenClose3D::DebugOn()
{
this->vtkObject::DebugOn();
if (this->Filter0)
{
this->Filter0->DebugOn();
}
if (this->Filter1)
{
this->Filter1->DebugOn();
}
}
//----------------------------------------------------------------------------
void vtkImageOpenClose3D::DebugOff()
{
this->vtkObject::DebugOff();
if (this->Filter0)
{
this->Filter0->DebugOff();
}
if (this->Filter1)
{
this->Filter1->DebugOff();
}
}
//----------------------------------------------------------------------------
// Pass modified message to sub filters.
void vtkImageOpenClose3D::Modified()
{
this->vtkObject::Modified();
if (this->Filter0)
{
this->Filter0->Modified();
}
if (this->Filter1)
{
this->Filter1->Modified();
}
}
//----------------------------------------------------------------------------
// This method considers the sub filters MTimes when computing this objects
// MTime
unsigned long int vtkImageOpenClose3D::GetMTime()
{
unsigned long int t1, t2;
t1 = this->Superclass::GetMTime();
if (this->Filter0)
{
t2 = this->Filter0->GetMTime();
if (t2 > t1)
{
t1 = t2;
}
}
if (this->Filter1)
{
t2 = this->Filter1->GetMTime();
if (t2 > t1)
{
t1 = t2;
}
}
return t1;
}
//----------------------------------------------------------------------------
int
vtkImageOpenClose3D::ComputePipelineMTime(vtkInformation* request,
vtkInformationVector** inInfoVec,
vtkInformationVector* outInfoVec,
int requestFromOutputPort,
unsigned long* mtime)
{
// Process the request on the internal pipeline. Share our input
// information with the first filter and our output information with
// the last filter.
vtkExecutive* exec0 = this->Filter0->GetExecutive();
vtkExecutive* exec1 = this->Filter1->GetExecutive();
exec0->SetSharedInputInformation(inInfoVec);
exec1->SetSharedOutputInformation(outInfoVec);
unsigned long mtime1;
if(exec1->ComputePipelineMTime(request,
exec1->GetInputInformation(),
exec1->GetOutputInformation(),
requestFromOutputPort, &mtime1))
{
// Now run the request in this algorithm.
return this->Superclass::ComputePipelineMTime(request,
inInfoVec, outInfoVec,
requestFromOutputPort,
mtime);
}
else
{
// The internal pipeline failed to process the request.
vtkErrorMacro("Internal pipeline failed to process pipeline modified "
"time request.");
return 0;
}
}
//----------------------------------------------------------------------------
int vtkImageOpenClose3D::ProcessRequest(vtkInformation* request,
vtkInformationVector** inInfoVec,
vtkInformationVector* outInfoVec)
{
// Process the request on the internal pipeline. Share our input
// information with the first filter and our output information with
// the last filter.
vtkExecutive* exec0 = this->Filter0->GetExecutive();
vtkExecutive* exec1 = this->Filter1->GetExecutive();
exec0->SetSharedInputInformation(inInfoVec);
exec1->SetSharedOutputInformation(outInfoVec);
return exec1->ProcessRequest(request,
exec1->GetInputInformation(),
exec1->GetOutputInformation());
}
//----------------------------------------------------------------------------
// Selects the size of gaps or objects removed.
void vtkImageOpenClose3D::SetKernelSize(int size0, int size1, int size2)
{
if ( ! this->Filter0 || ! this->Filter1)
{
vtkErrorMacro(<< "SetKernelSize: Sub filter not created yet.");
return;
}
this->Filter0->SetKernelSize(size0, size1, size2);
this->Filter1->SetKernelSize(size0, size1, size2);
// Sub filters take care of modified.
}
//----------------------------------------------------------------------------
// Determines the value that will closed.
// Close value is first dilated, and then eroded
void vtkImageOpenClose3D::SetCloseValue(double value)
{
if ( ! this->Filter0 || ! this->Filter1)
{
vtkErrorMacro(<< "SetCloseValue: Sub filter not created yet.");
return;
}
this->Filter0->SetDilateValue(value);
this->Filter1->SetErodeValue(value);
}
//----------------------------------------------------------------------------
double vtkImageOpenClose3D::GetCloseValue()
{
if ( ! this->Filter0)
{
vtkErrorMacro(<< "GetCloseValue: Sub filter not created yet.");
return 0.0;
}
return this->Filter0->GetDilateValue();
}
//----------------------------------------------------------------------------
// Determines the value that will opened.
// Open value is first eroded, and then dilated.
void vtkImageOpenClose3D::SetOpenValue(double value)
{
if ( ! this->Filter0 || ! this->Filter1)
{
vtkErrorMacro(<< "SetOpenValue: Sub filter not created yet.");
return;
}
this->Filter0->SetErodeValue(value);
this->Filter1->SetDilateValue(value);
}
//----------------------------------------------------------------------------
double vtkImageOpenClose3D::GetOpenValue()
{
if ( ! this->Filter0)
{
vtkErrorMacro(<< "GetOpenValue: Sub filter not created yet.");
return 0.0;
}
return this->Filter0->GetErodeValue();
}
//----------------------------------------------------------------------------
void vtkImageOpenClose3D::ReportReferences(vtkGarbageCollector* collector)
{
this->Superclass::ReportReferences(collector);
// These filters share our input and are therefore involved in a
// reference loop.
vtkGarbageCollectorReport(collector, this->Filter0, "Filter0");
vtkGarbageCollectorReport(collector, this->Filter1, "Filter1");
}
|