Commit 3c535009 authored by Mathieu Westphal's avatar Mathieu Westphal Committed by Kitware Robot
Browse files

Merge topic 'ForceTime'

f53711be

 Force Time Filter
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !1180
parents 1870ef33 f53711be
Pipeline #6726 failed with stage
......@@ -5,6 +5,7 @@ set(Module_SRCS
vtkDSPFilterGroup.cxx
vtkEarthSource.cxx
vtkFacetReader.cxx
vtkForceTime.cxx
vtkGreedyTerrainDecimation.cxx
vtkGridTransform.cxx
vtkImageToPolyDataFilter.cxx
......
......@@ -2,6 +2,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TemporalStatistics.cxx
TestBSplineTransform.cxx
TestDepthSortPolyData.cxx
TestForceTime.cxx
TestPolyDataSilhouette.cxx
TestProcrustesAlignmentFilter.cxx,NO_VALID
TestTemporalCacheSimple.cxx,NO_VALID
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestForceTime.cxx
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 <vtkActor.h>
#include <vtkDataSetMapper.h>
#include <vtkDataSetTriangleFilter.h>
#include <vtkDoubleArray.h>
#include <vtkForceTime.h>
#include <vtkImageData.h>
#include <vtkInformation.h>
#include <vtkInformationVector.h>
#include <vtkNew.h>
#include <vtkObjectFactory.h>
#include <vtkPointData.h>
#include <vtkRTAnalyticSource.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkStreamingDemandDrivenPipeline.h>
#include <vtkUnstructuredGrid.h>
class vtkTimeRTAnalyticSource : public vtkRTAnalyticSource
{
public:
static vtkTimeRTAnalyticSource *New();
vtkTypeMacro(vtkTimeRTAnalyticSource, vtkRTAnalyticSource);
protected:
vtkTimeRTAnalyticSource() {}
int RequestInformation(vtkInformation * request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
// get the info objects
vtkInformation *outInfo = outputVector->GetInformationObject(0);
double range[2] = {0, 5};
outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(),
range, 2);
double outTimes[6] = {0, 1, 2, 3, 4, 5};
outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(),
outTimes, 6);
vtkRTAnalyticSource::RequestInformation(request, inputVector, outputVector);
return 1;
}
virtual void ExecuteDataWithInformation(vtkDataObject *output, vtkInformation *outInfo)
{
Superclass::ExecuteDataWithInformation(output, outInfo);
// Split the update extent further based on piece request.
vtkImageData *data = vtkImageData::GetData(outInfo);
int* outExt = data->GetExtent();
// find the region to loop over
int maxX = (outExt[1] - outExt[0]) + 1;
int maxY = (outExt[3] - outExt[2]) + 1;
int maxZ = (outExt[5] - outExt[4]) + 1;
vtkNew<vtkDoubleArray> timeArray;
timeArray->SetName("timeData");
timeArray->SetNumberOfValues(maxX * maxY * maxZ);
data->GetPointData()->SetScalars(timeArray.Get());
double t = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP());
vtkIdType cnt = 0;
for (int idxZ = 0; idxZ < maxZ; idxZ++)
{
for (int idxY = 0; idxY < maxY; idxY++)
{
for (int idxX = 0; idxX < maxX; idxX++, cnt++)
{
timeArray->SetValue(cnt, t + idxX);
}
}
}
}
private:
vtkTimeRTAnalyticSource(const vtkTimeRTAnalyticSource&); // Not implemented.
void operator=(const vtkTimeRTAnalyticSource&); // Not implemented.
};
vtkStandardNewMacro(vtkTimeRTAnalyticSource);
//------------------------------------------------------------------------------
// Program main
int TestForceTime(int vtkNotUsed(argc), char* vtkNotUsed(argv)[])
{
// Create the pipeline to produce the initial grid
vtkNew<vtkTimeRTAnalyticSource> wavelet;
vtkNew<vtkDataSetTriangleFilter> tetrahedralize;
tetrahedralize->SetInputConnection(wavelet->GetOutputPort());
vtkNew<vtkForceTime> forceTime;
forceTime->SetInputConnection(tetrahedralize->GetOutputPort());
forceTime->SetForcedTime(1);
forceTime->IgnorePipelineTimeOn();
forceTime->UpdateInformation();
forceTime->GetOutputInformation(0)->Set(
vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP(), 2);
forceTime->Update();
if (vtkUnstructuredGrid::SafeDownCast(forceTime->GetOutput(0))
->GetPointData()->GetScalars()->GetTuple1(0) != 1)
{
std::cerr << "Incorrect data in force time output" << std::endl;
return EXIT_FAILURE;
}
vtkNew<vtkDataSetMapper> mapper;
mapper->SetInputConnection(forceTime->GetOutputPort());
mapper->SetScalarRange(0, 30);
vtkNew<vtkActor> actor;
actor->SetMapper(mapper.Get());
vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer(renderer.Get());
vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
renderWindowInteractor->SetRenderWindow(renderWindow.Get());
renderer->AddActor(actor.Get());
renderer->SetBackground(.3, .6, .3); // Background color green
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkForceTime.cxx
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 "vtkForceTime.h"
#include "vtkDataObject.h"
#include "vtkDataObjectTypes.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkStreamingDemandDrivenPipeline.h"
vtkStandardNewMacro(vtkForceTime);
//----------------------------------------------------------------------------
vtkForceTime::vtkForceTime()
{
this->ForcedTime = 0.0;
this->IgnorePipelineTime = true;
this->Cache = NULL;
this->PipelineTime = -1;
this->PipelineTimeFlag = false;
}
//----------------------------------------------------------------------------
vtkForceTime::~vtkForceTime()
{
if (this->Cache != NULL)
{
this->Cache->Delete();
this->Cache = NULL;
}
}
//----------------------------------------------------------------------------
void vtkForceTime::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "ForcedTime: " << this->ForcedTime << endl;
os << indent << "IgnorePipelineTime: " << this->IgnorePipelineTime << endl;
}
//----------------------------------------------------------------------------
int vtkForceTime::RequestInformation(vtkInformation * vtkNotUsed(request),
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
// get the info objects
vtkInformation *outInfo = outputVector->GetInformationObject(0);
vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
if (inInfo->Has(vtkStreamingDemandDrivenPipeline::TIME_RANGE()))
{
double range[2];
inInfo->Get(vtkStreamingDemandDrivenPipeline::TIME_RANGE(), range);
if (this->IgnorePipelineTime)
{
range[0] = this->ForcedTime;
range[1] = this->ForcedTime;
}
outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(),
range, 2);
}
if (inInfo->Has(vtkStreamingDemandDrivenPipeline::TIME_STEPS()))
{
double *inTimes =
inInfo->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
int numTimes =
inInfo->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
double *outTimes;
if (this->IgnorePipelineTime)
{
outTimes = new double [numTimes];
for (int i = 0; i < numTimes; i++)
{
outTimes[i] = this->ForcedTime;
}
}
else
{
outTimes = inTimes;
}
outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(),
outTimes, numTimes);
if (this->IgnorePipelineTime)
{
delete [] outTimes;
}
}
// Upstream filters changed, invalidate cache
if (this->IgnorePipelineTime && this->Cache)
{
this->Cache->Delete();
this->Cache = NULL;
}
return 1;
}
//----------------------------------------------------------------------------
int vtkForceTime::RequestData(vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
vtkDataObject* inData = vtkDataObject::GetData(inputVector[0], 0);
vtkDataObject* outData = vtkDataObject::GetData(outputVector, 0);
if (!inData)
{
return 1;
}
// Filter is "disabled", just pass input data
if (!this->IgnorePipelineTime)
{
outData->ShallowCopy(inData);
return 1;
}
// Create Cache
if (!this->Cache)
{
request->Set(vtkStreamingDemandDrivenPipeline::CONTINUE_EXECUTING(), 1);
this->Cache = vtkDataObjectTypes::NewDataObject(inData->GetClassName());
this->Cache->DeepCopy(inData);
this->PipelineTimeFlag = true;
}
else if (this->PipelineTimeFlag)
{
// Stop the pipeline loop
request->Remove(vtkStreamingDemandDrivenPipeline::CONTINUE_EXECUTING());
this->PipelineTimeFlag = false;
}
outData->ShallowCopy(this->Cache);
return 1;
}
//----------------------------------------------------------------------------
int vtkForceTime::RequestUpdateExtent(vtkInformation* vtkNotUsed(request),
vtkInformationVector** inputVector,
vtkInformationVector* vtkNotUsed(outputVector))
{
vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
if (this->IgnorePipelineTime && !this->Cache)
{
double *inTimes = inInfo->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
if (inTimes)
{
// Save current pipeline time step
this->PipelineTime =
inInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP());
inInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP(),
this->ForcedTime);
}
}
else if (this->PipelineTimeFlag)
{
// Restore pipeline time
double *inTimes = inInfo->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
if (inTimes)
{
inInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP(),
this->PipelineTime);
}
}
return 1;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkForceTime.h
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.
=========================================================================*/
#ifndef vtkForceTime_h
#define vtkForceTime_h
#include "vtkFiltersHybridModule.h" // For export macro
#include "vtkPassInputTypeAlgorithm.h"
class VTKFILTERSHYBRID_EXPORT vtkForceTime : public vtkPassInputTypeAlgorithm
{
public :
static vtkForceTime* New();
vtkTypeMacro(vtkForceTime, vtkPassInputTypeAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Replace the pipeline time by this one.
vtkSetMacro(ForcedTime, double);
vtkGetMacro(ForcedTime, double);
// Description:
// Use the ForcedTime. If disabled, use usual pipeline time.
vtkSetMacro(IgnorePipelineTime, bool);
vtkGetMacro(IgnorePipelineTime, bool);
vtkBooleanMacro(IgnorePipelineTime, bool);
protected:
vtkForceTime();
virtual ~vtkForceTime();
virtual int RequestUpdateExtent(vtkInformation*,
vtkInformationVector**,
vtkInformationVector*);
virtual int RequestInformation(vtkInformation*,
vtkInformationVector**,
vtkInformationVector*);
virtual int RequestData(vtkInformation*,
vtkInformationVector**,
vtkInformationVector*);
private:
vtkForceTime(const vtkForceTime&); // Not implemented.
void operator=(const vtkForceTime&); // Not implemented.
double ForcedTime;
bool IgnorePipelineTime;
double PipelineTime;
bool PipelineTimeFlag;
vtkDataObject* Cache;
};
#endif //vtkForceTime_h
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment