Commit 56788e10 authored by Berk Geveci's avatar Berk Geveci
Browse files

Made more progress

parent 16092733
......@@ -1291,12 +1291,6 @@ int vtkFreeTypeUtilities::RenderString(vtkTextProperty *tprop,
return 0;
}
if (data->GetNumberOfScalarComponents() > 4)
{
vtkErrorMacro("The image data must have a maximum of four components");
return 0;
}
// Prepare the ImageData to receive the text
int x = 0;
int y = 0;
......@@ -1786,8 +1780,6 @@ void vtkFreeTypeUtilities::PrepareImageData(vtkImageData *data,
// If the RGBA image data is too small, resize it to the next power of 2
// WARNING: at this point, since this image is going to be a texture
// we should limit its size or query the hardware
data->SetScalarTypeToUnsignedChar();
data->SetNumberOfScalarComponents(4);
data->SetSpacing(1.0, 1.0, 1.0);
// If the current image data is too small to render the text,
......@@ -1795,7 +1787,9 @@ void vtkFreeTypeUtilities::PrepareImageData(vtkImageData *data,
int img_dims[3], new_img_dims[3];
data->GetDimensions(img_dims);
if (img_dims[0] < text_size[0] || img_dims[1] < text_size[1] ||
if (data->GetScalarType() != VTK_UNSIGNED_CHAR ||
data->GetNumberOfScalarComponents() != 4 ||
img_dims[0] < text_size[0] || img_dims[1] < text_size[1] ||
text_size[0] * 2 < img_dims[0] || text_size[1] * 2 < img_dims[0])
{
new_img_dims[0] = 1 << static_cast<int>(ceil(log(static_cast<double>(text_size[0])) / log(2.0)));
......@@ -1816,10 +1810,7 @@ void vtkFreeTypeUtilities::PrepareImageData(vtkImageData *data,
new_img_dims[2] != img_dims[2])
{
data->SetDimensions(new_img_dims);
data->AllocateScalars();
data->UpdateInformation();
data->SetUpdateExtent(data->GetWholeExtent());
data->PropagateUpdateExtent();
data->AllocateScalars(VTK_UNSIGNED_CHAR, 4);
}
}
......
......@@ -298,7 +298,7 @@ void vtkIVExporter::WriteAnActor(vtkActor *anActor, FILE *fp)
}
else
{
ds->Update();
anActor->GetMapper()->GetInputAlgorithm()->Update();
pd = static_cast<vtkPolyData *>(ds);
}
......@@ -354,7 +354,7 @@ void vtkIVExporter::WriteAnActor(vtkActor *anActor, FILE *fp)
vtkErrorMacro(<< "texture has no input!\n");
return;
}
aTexture->GetInput()->Update();
aTexture->GetInputAlgorithm()->Update();
size = aTexture->GetInput()->GetDimensions();
scalars = aTexture->GetInput()->GetPointData()->GetScalars();
......
......@@ -21,6 +21,8 @@
#include "vtkRenderer.h"
#include "vtkImageProperty.h"
#include "vtkImageSliceMapper.h"
#include "vtkInformation.h"
#include "vtkStreamingDemandDrivenPipeline.h"
vtkStandardNewMacro(vtkImageActor);
......@@ -74,6 +76,17 @@ void vtkImageActor::SetInput(vtkImageData *input)
}
}
//----------------------------------------------------------------------------
vtkAlgorithm *vtkImageActor::GetInputAlgorithm()
{
if (!this->Mapper)
{
return 0;
}
return this->Mapper->GetInputAlgorithm();
}
//----------------------------------------------------------------------------
vtkImageData *vtkImageActor::GetInput()
{
......@@ -240,23 +253,33 @@ void vtkImageActor::GetDisplayExtent(int extent[6])
// Get the bounds for this Volume as (Xmin,Xmax,Ymin,Ymax,Zmin,Zmax).
double *vtkImageActor::GetDisplayBounds()
{
vtkImageData *input = 0;
vtkAlgorithm* inputAlg = this->Mapper->GetInputAlgorithm();
if (this->Mapper)
{
input = this->Mapper->GetInput();
inputAlg = this->Mapper->GetInputAlgorithm();
}
if (!this->Mapper || !input)
if (!this->Mapper || !inputAlg)
{
return this->DisplayBounds;
}
input->UpdateInformation();
inputAlg->UpdateInformation();
int extent[6];
input->GetWholeExtent(extent);
double *spacing = input->GetSpacing();
double *origin = input->GetOrigin();
vtkInformation* inputInfo =
this->Mapper->GetInputInformation();
inputInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), extent);
double spacing[3] = {1, 1, 1};
if (inputInfo->Has(vtkDataObject::SPACING()))
{
inputInfo->Get(vtkDataObject::SPACING(), spacing);
}
double origin[3] = {0, 0, 0};
if (inputInfo->Has(vtkDataObject::ORIGIN()))
{
inputInfo->Get(vtkDataObject::ORIGIN(), origin);
}
// if the display extent has not been set, use first slice
extent[5] = extent[4];
......@@ -419,12 +442,13 @@ int vtkImageActor::GetWholeZMin()
{
int *extent;
if ( ! this->GetInput())
if ( ! this->GetInputAlgorithm())
{
return 0;
}
this->GetInput()->UpdateInformation();
extent = this->GetInput()->GetWholeExtent();
this->GetInputAlgorithm()->UpdateInformation();
extent = this->Mapper->GetInputInformation()->Get(
vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
return extent[4];
}
......@@ -433,12 +457,13 @@ int vtkImageActor::GetWholeZMax()
{
int *extent;
if ( ! this->GetInput())
if ( ! this->GetInputAlgorithm())
{
return 0;
}
this->GetInput()->UpdateInformation();
extent = this->GetInput()->GetWholeExtent();
this->GetInputAlgorithm()->UpdateInformation();
extent = this->Mapper->GetInputInformation()->Get(
vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
return extent[5];
}
......
......@@ -30,6 +30,7 @@
#include "vtkImageSlice.h"
class vtkAlgorithm;
class vtkPropCollection;
class vtkRenderer;
class vtkImageData;
......@@ -132,6 +133,9 @@ protected:
int DisplayExtent[6];
double DisplayBounds[6];
// Convenience function that returns the input of the mapper
vtkAlgorithm *GetInputAlgorithm();
private:
vtkImageActor(const vtkImageActor&); // Not implemented.
void operator=(const vtkImageActor&); // Not implemented.
......
......@@ -20,6 +20,7 @@
#include "vtkImageData.h"
#include "vtkImagingFactory.h"
#include "vtkInformation.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkViewport.h"
#include "vtkWindow.h"
......@@ -140,21 +141,22 @@ void vtkImageMapper::RenderStart(vtkViewport* viewport, vtkActor2D* actor)
}
if (!this->GetInput())
if (!this->GetInputAlgorithm())
{
vtkDebugMacro(<< "vtkImageMapper::Render - Please Set the input.");
return;
}
this->GetInput()->UpdateInformation();
this->GetInputAlgorithm()->UpdateInformation();
vtkInformation* inInfo = this->GetInputInformation();
if (!this->UseCustomExtents)
{
// start with the wholeExtent
int wholeExtent[6];
memcpy(wholeExtent,this->GetInput()->GetWholeExtent(),6*sizeof(int));
memcpy(this->DisplayExtent,
this->GetInput()->GetWholeExtent(),6*sizeof(int));
inInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), wholeExtent);
inInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), this->DisplayExtent);
// Set The z values to the zslice
this->DisplayExtent[4] = this->ZSlice;
this->DisplayExtent[5] = this->ZSlice;
......@@ -211,7 +213,8 @@ void vtkImageMapper::RenderStart(vtkViewport* viewport, vtkActor2D* actor)
return;
}
this->GetInput()->SetUpdateExtent(this->DisplayExtent);
vtkStreamingDemandDrivenPipeline::SetUpdateExtent(
this->GetInputInformation(), this->DisplayExtent);
// set the position adjustment
this->PositionAdjustment[0] = this->DisplayExtent[0];
......@@ -226,14 +229,15 @@ void vtkImageMapper::RenderStart(vtkViewport* viewport, vtkActor2D* actor)
this->DisplayExtent[4] = this->ZSlice;
this->DisplayExtent[5] = this->ZSlice;
//
this->GetInput()->SetUpdateExtentToWholeExtent();
vtkStreamingDemandDrivenPipeline::SetUpdateExtentToWholeExtent(
this->GetInputInformation());
// clear the position adjustment
this->PositionAdjustment[0] = 0;
this->PositionAdjustment[1] = 0;
}
// Get the region from the input
this->GetInput()->Update();
this->GetInputAlgorithm()->Update();
data = this->GetInput();
if ( !data)
{
......@@ -253,8 +257,9 @@ int vtkImageMapper::GetWholeZMin()
{
return 0;
}
this->GetInput()->UpdateInformation();
extent = this->GetInput()->GetWholeExtent();
this->GetInputAlgorithm()->UpdateInformation();
extent = this->GetInputInformation()->Get(
vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
return extent[4];
}
......@@ -267,8 +272,9 @@ int vtkImageMapper::GetWholeZMax()
{
return 0;
}
this->GetInput()->UpdateInformation();
extent = this->GetInput()->GetWholeExtent();
this->GetInputAlgorithm()->UpdateInformation();
extent = this->GetInputInformation()->Get(
vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
return extent[5];
}
......
......@@ -411,9 +411,9 @@ unsigned long vtkImageSlice::GetRedrawMTime()
{
time = this->Mapper->GetMTime();
mTime = ( time > mTime ? time : mTime );
if (this->GetMapper()->GetInput() != NULL)
if (this->GetMapper()->GetInputAlgorithm() != NULL)
{
this->GetMapper()->GetInput()->Update();
this->GetMapper()->GetInputAlgorithm()->Update();
time = this->Mapper->GetInput()->GetMTime();
mTime = ( time > mTime ? time : mTime );
}
......
......@@ -17,10 +17,12 @@
#include "vtkActor2D.h"
#include "vtkCommand.h"
#include "vtkImageData.h"
#include "vtkInformation.h"
#include "vtkInteractorStyleImage.h"
#include "vtkObjectFactory.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkStreamingDemandDrivenPipeline.h"
vtkStandardNewMacro(vtkImageViewer);
......@@ -108,10 +110,12 @@ public:
if (event == vtkCommand::ResetWindowLevelEvent)
{
this->IV->GetInput()->UpdateInformation();
this->IV->GetInput()->SetUpdateExtent
(this->IV->GetInput()->GetWholeExtent());
this->IV->GetInput()->Update();
this->IV->GetInputAlgorithm()->UpdateInformation();
vtkStreamingDemandDrivenPipeline::SetUpdateExtent(
this->IV->GetInputAlgorithm()->GetOutputInformation(0),
vtkStreamingDemandDrivenPipeline::GetWholeExtent(
this->IV->GetInputAlgorithm()->GetOutputInformation(0)));
this->IV->GetInputAlgorithm()->Update();
double *range = this->IV->GetInput()->GetScalarRange();
this->IV->SetColorWindow(range[1] - range[0]);
this->IV->SetColorLevel(0.5 * (range[1] + range[0]));
......@@ -237,8 +241,9 @@ void vtkImageViewer::Render()
if (this->RenderWindow->GetSize()[0] == 0 && this->ImageMapper->GetInput())
{
// get the size from the mappers input
this->ImageMapper->GetInput()->UpdateInformation();
int *ext = this->ImageMapper->GetInput()->GetWholeExtent();
this->ImageMapper->GetInputAlgorithm()->UpdateInformation();
int *ext = this->ImageMapper->GetInputInformation()->Get(
vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
// if it would be smaller than 150 by 100 then limit to 150 by 100
int xs = ext[1] - ext[0] + 1;
int ys = ext[3] - ext[2] + 1;
......@@ -274,6 +279,12 @@ void vtkImageViewer::OffScreenRenderingOff()
this->SetOffScreenRendering(0);
}
//----------------------------------------------------------------------------
vtkAlgorithm* vtkImageViewer::GetInputAlgorithm()
{
return this->ImageMapper->GetInputAlgorithm();
}
#ifndef VTK_LEGACY_REMOVE
int vtkImageViewer::GetGrayScaleHint()
{
......
......@@ -131,6 +131,9 @@ protected:
vtkRenderWindowInteractor *Interactor;
vtkInteractorStyleImage *InteractorStyle;
friend class vtkImageViewerCallback;
vtkAlgorithm* GetInputAlgorithm();
private:
vtkImageViewer(const vtkImageViewer&); // Not implemented.
void operator=(const vtkImageViewer&); // Not implemented.
......
......@@ -20,11 +20,13 @@
#include "vtkImageData.h"
#include "vtkImageData.h"
#include "vtkImageMapToWindowLevelColors.h"
#include "vtkInformation.h"
#include "vtkInteractorStyleImage.h"
#include "vtkObjectFactory.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkStreamingDemandDrivenPipeline.h"
vtkStandardNewMacro(vtkImageViewer2);
......@@ -191,11 +193,12 @@ int* vtkImageViewer2::GetSize()
//----------------------------------------------------------------------------
void vtkImageViewer2::GetSliceRange(int &min, int &max)
{
vtkImageData *input = this->GetInput();
vtkAlgorithm *input = this->GetInputAlgorithm();
if (input)
{
input->UpdateInformation();
int *w_ext = input->GetWholeExtent();
int *w_ext = input->GetOutputInformation(0)->Get(
vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
min = w_ext[this->SliceOrientation * 2];
max = w_ext[this->SliceOrientation * 2 + 1];
}
......@@ -204,11 +207,13 @@ void vtkImageViewer2::GetSliceRange(int &min, int &max)
//----------------------------------------------------------------------------
int* vtkImageViewer2::GetSliceRange()
{
vtkImageData *input = this->GetInput();
vtkAlgorithm *input = this->GetInputAlgorithm();
if (input)
{
input->UpdateInformation();
return input->GetWholeExtent() + this->SliceOrientation * 2;
return input->GetOutputInformation(0)->Get(
vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()) +
this->SliceOrientation * 2;
}
return NULL;
}
......@@ -335,14 +340,16 @@ void vtkImageViewer2::UpdateOrientation()
//----------------------------------------------------------------------------
void vtkImageViewer2::UpdateDisplayExtent()
{
vtkImageData *input = this->GetInput();
vtkAlgorithm *input = this->GetInputAlgorithm();
if (!input || !this->ImageActor)
{
return;
}
input->UpdateInformation();
int *w_ext = input->GetWholeExtent();
vtkInformation* outInfo = input->GetOutputInformation(0);
int *w_ext = outInfo->Get(
vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
// Is the slice in range ? If not, fix it
......@@ -392,7 +399,7 @@ void vtkImageViewer2::UpdateDisplayExtent()
double spos = bounds[this->SliceOrientation * 2];
double cpos = cam->GetPosition()[this->SliceOrientation];
double range = fabs(spos - cpos);
double *spacing = input->GetSpacing();
double *spacing = outInfo->Get(vtkDataObject::SPACING());
double avg_spacing =
(spacing[0] + spacing[1] + spacing[2]) / 3.0;
cam->SetClippingRange(
......@@ -475,10 +482,12 @@ public:
if (event == vtkCommand::ResetWindowLevelEvent)
{
this->IV->GetInput()->UpdateInformation();
this->IV->GetInput()->SetUpdateExtent
(this->IV->GetInput()->GetWholeExtent());
this->IV->GetInput()->Update();
this->IV->GetInputAlgorithm()->UpdateInformation();
vtkStreamingDemandDrivenPipeline::SetUpdateExtent(
this->IV->GetInputInformation(),
vtkStreamingDemandDrivenPipeline::GetWholeExtent(
this->IV->GetInputInformation()));
this->IV->GetInputAlgorithm()->Update();
double *range = this->IV->GetInput()->GetScalarRange();
this->IV->SetColorWindow(range[1] - range[0]);
this->IV->SetColorLevel(0.5 * (range[1] + range[0]));
......@@ -641,11 +650,12 @@ void vtkImageViewer2::Render()
{
// Initialize the size if not set yet
vtkImageData *input = this->GetInput();
vtkAlgorithm *input = this->GetInputAlgorithm();
if (input)
{
input->UpdateInformation();
int *w_ext = input->GetWholeExtent();
int *w_ext = this->GetInputInformation()->Get(
vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
int xs = 0, ys = 0;
switch (this->SliceOrientation)
......@@ -718,6 +728,16 @@ vtkImageData* vtkImageViewer2::GetInput()
{
return vtkImageData::SafeDownCast(this->WindowLevel->GetInput());
}
//----------------------------------------------------------------------------
vtkInformation* vtkImageViewer2::GetInputInformation()
{
return this->WindowLevel->GetInputInformation();
}
//----------------------------------------------------------------------------
vtkAlgorithm* vtkImageViewer2::GetInputAlgorithm()
{
return this->WindowLevel->GetInputAlgorithm();
}
//----------------------------------------------------------------------------
void vtkImageViewer2::SetInputConnection(vtkAlgorithmOutput* input)
......
......@@ -56,10 +56,12 @@
#include "vtkObject.h"
class vtkAlgorithm;
class vtkAlgorithmOutput;
class vtkImageActor;
class vtkImageData;
class vtkImageMapToWindowLevelColors;
class vtkInformation;
class vtkInteractorStyleImage;
class vtkRenderWindow;
class vtkRenderer;
......@@ -221,6 +223,11 @@ protected:
virtual void UpdateOrientation();
vtkAlgorithm* GetInputAlgorithm();
vtkInformation* GetInputInformation();
friend class vtkImageViewer2Callback;
private:
vtkImageViewer2(const vtkImageViewer2&); // Not implemented.
void operator=(const vtkImageViewer2&); // Not implemented.
......
......@@ -334,7 +334,7 @@ void vtkLabeledTreeMapDataMapper::RenderOpaqueGeometry(vtkViewport *viewport,
return;
}
input->Update();
this->GetInputAlgorithm()->Update();
// Input might have changed
input = this->GetInputTree();
......
......@@ -608,8 +608,6 @@ void vtkMapper::MapScalarsToTexture(vtkDataArray* scalars, double alpha)
this->ColorTextureMap = vtkImageData::New();
this->ColorTextureMap->SetExtent(0,ColorTextureMapSize-1,
0,0, 0,0);
this->ColorTextureMap->SetNumberOfScalarComponents(4);
this->ColorTextureMap->SetScalarTypeToUnsignedChar();
this->ColorTextureMap->GetPointData()->SetScalars(
this->LookupTable->MapScalars(tmp, this->ColorMode, 0));
this->LookupTable->SetAlpha(orig_alpha);
......
......@@ -164,7 +164,7 @@ void vtkOBJExporter::WriteAnActor(vtkActor *anActor, FILE *fpObj, FILE *fpMtl,
{
return;
}
ds->Update();
anActor->GetMapper()->GetInputAlgorithm()->Update();
trans->SetMatrix(anActor->vtkProp3D::GetMatrix());
// we really want polydata
......
......@@ -303,7 +303,7 @@ void vtkOOGLExporter::WriteAnActor(vtkActor *anActor, FILE *fp, int count)
}
else
{
ds->Update();
anActor->GetMapper()->GetInputAlgorithm()->Update();
pd = static_cast<vtkPolyData *>(ds);
}
......@@ -337,7 +337,7 @@ void vtkOOGLExporter::WriteAnActor(vtkActor *anActor, FILE *fp, int count)
vtkErrorMacro(<< "texture has no input!\n");
return;
}
aTexture->GetInput()->Update();
aTexture->GetInputAlgorithm()->Update();
size = aTexture->GetInput()->GetDimensions();
scalars = aTexture->GetInput()->GetPointData()->GetScalars();
......
......@@ -341,7 +341,7 @@ void vtkPOVExporter::WriteActor(vtkActor *actor)
{
return;
}
dataset->Update();
actor->GetMapper()->GetInputAlgorithm()->Update();
// convert non polygon data to polygon data if needed
vtkGeometryFilter *geometryFilter = NULL;
......
......@@ -314,7 +314,7 @@ void vtkPainterPolyDataMapper::RenderPiece(vtkRenderer* ren, vtkActor* act)
this->InvokeEvent(vtkCommand::StartEvent,NULL);
if (!this->Static)
{
input->Update();
this->GetInputAlgorithm()->Update();
}
this->InvokeEvent(vtkCommand::EndEvent,NULL);
......
......@@ -229,8 +229,6 @@ int vtkParallelCoordinatesActor::RenderOpaqueGeometry(vtkViewport *viewport)
// Check modified time to see whether we have to rebuild.
this->Input->Update();
if (positionsHaveChanged ||
this->GetMTime() > this->BuildTime ||
this->Input->GetMTime() > this->BuildTime ||
......
......@@ -20,6 +20,7 @@
#include "vtkMath.h"
#include "vtkPolyData.h"
#include "vtkRenderWindow.h"
#include "vtkStreamingDemandDrivenPipeline.h"
//----------------------------------------------------------------------------
......@@ -54,9 +55,9 @@ void vtkPolyDataMapper::Render(vtkRenderer *ren, vtkActor *act)
}
int currentPiece, nPieces;
vtkDataObject *input = this->GetInputDataObject(0, 0);
vtkInformation *inInfo = this->GetInputInformation();
if (input == NULL)
if (inInfo == NULL)
{
vtkErrorMacro("Mapper has no input.");
return;
......@@ -68,7 +69,9 @@ void vtkPolyDataMapper::Render(vtkRenderer *ren, vtkActor *act)
{
// If more than one pieces, render in loop.
currentPiece = this->NumberOfSubPieces * this->Piece + i;
input->SetUpdateExtent(currentPiece, nPieces, this->GhostLevel);
vtkStreamingDemandDrivenPipeline::SetUpdateExtent(
inInfo,
currentPiece, nPieces, this->GhostLevel);
this->RenderPiece(ren, act);
}
}
......@@ -104,15 +107,18 @@ void vtkPolyDataMapper::Update()
}
int currentPiece, nPieces = this->NumberOfPieces;
vtkPolyData* input = this->GetInput();
vtkInformation* inInfo = this->GetInputInformation();
// If the estimated pipeline memory usage is larger than
// the memory limit, break the current piece into sub-pieces.
if (input)
if (inInfo)
{
currentPiece = this->NumberOfSubPieces * this->Piece;