| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include "PreCompiled.h" |
| |
|
| | #ifndef _PreComp_ |
| | # include <cmath> |
| | # include <algorithm> |
| | # include <iterator> |
| | # include <vector> |
| | # include <vtkUnstructuredGrid.h> |
| | # include <vtkMultiBlockDataSet.h> |
| | # include <vtkFieldData.h> |
| | # include <vtkStreamingDemandDrivenPipeline.h> |
| | # include <vtkFloatArray.h> |
| | # include <vtkInformation.h> |
| | # include <vtkInformationVector.h> |
| | #endif |
| |
|
| | #include "vtkFemFrameSourceAlgorithm.h" |
| |
|
| | using namespace Fem; |
| |
|
| |
|
| | vtkStandardNewMacro(vtkFemFrameSourceAlgorithm); |
| |
|
| | vtkFemFrameSourceAlgorithm::vtkFemFrameSourceAlgorithm() |
| | { |
| | |
| | SetNumberOfInputPorts(0); |
| | SetNumberOfOutputPorts(1); |
| | } |
| |
|
| | vtkFemFrameSourceAlgorithm::~vtkFemFrameSourceAlgorithm() = default; |
| |
|
| | void vtkFemFrameSourceAlgorithm::setDataObject(vtkSmartPointer<vtkDataObject> data) |
| | { |
| | m_data = data; |
| | Modified(); |
| | Update(); |
| | } |
| |
|
| | bool vtkFemFrameSourceAlgorithm::isValid() |
| | { |
| | return m_data.GetPointer() ? true : false; |
| | } |
| |
|
| | std::vector<double> vtkFemFrameSourceAlgorithm::getFrameValues() |
| | { |
| |
|
| | |
| | if (!m_data || !m_data->IsA("vtkMultiBlockDataSet")) { |
| | return std::vector<double>(); |
| | } |
| |
|
| | |
| | vtkSmartPointer<vtkMultiBlockDataSet> multiblock = vtkMultiBlockDataSet::SafeDownCast(m_data); |
| |
|
| | unsigned long nblocks = multiblock->GetNumberOfBlocks(); |
| | std::vector<double> tFrames(nblocks); |
| |
|
| | for (unsigned long i = 0; i < nblocks; i++) { |
| |
|
| | vtkDataObject* block = multiblock->GetBlock(i); |
| | |
| | if (!block->GetFieldData()->HasArray("TimeValue")) { |
| | |
| | return std::vector<double>(); |
| | } |
| |
|
| | |
| | vtkDataArray* TimeValue = block->GetFieldData()->GetArray("TimeValue"); |
| | if (!TimeValue->IsA("vtkFloatArray") || TimeValue->GetNumberOfTuples() < 1) { |
| | |
| | return std::vector<double>(); |
| | } |
| |
|
| | tFrames[i] = vtkFloatArray::SafeDownCast(TimeValue)->GetValue(0); |
| | } |
| |
|
| | return tFrames; |
| | } |
| |
|
| | int vtkFemFrameSourceAlgorithm::RequestInformation( |
| | vtkInformation* reqInfo, |
| | vtkInformationVector** inVector, |
| | vtkInformationVector* outVector |
| | ) |
| | { |
| |
|
| | |
| | if (!this->Superclass::RequestInformation(reqInfo, inVector, outVector)) { |
| | return 0; |
| | } |
| |
|
| | if (!m_data) { |
| | |
| | return 1; |
| | } |
| |
|
| | std::vector<double> frames = getFrameValues(); |
| |
|
| | if (frames.empty()) { |
| | |
| | return 1; |
| | } |
| |
|
| | double tRange[2] = {frames.front(), frames.back()}; |
| |
|
| | |
| | vtkInformation* info = outVector->GetInformationObject(0); |
| | info->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(), tRange, 2); |
| | info->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(), &frames[0], frames.size()); |
| | info->Set(CAN_HANDLE_PIECE_REQUEST(), 1); |
| |
|
| | return 1; |
| | } |
| |
|
| | int vtkFemFrameSourceAlgorithm::RequestData( |
| | vtkInformation*, |
| | vtkInformationVector**, |
| | vtkInformationVector* outVector |
| | ) |
| | { |
| | vtkInformation* outInfo = outVector->GetInformationObject(0); |
| | vtkUnstructuredGrid* output = vtkUnstructuredGrid::SafeDownCast( |
| | outInfo->Get(vtkDataObject::DATA_OBJECT()) |
| | ); |
| |
|
| | if (!output) { |
| | return 0; |
| | } |
| |
|
| | if (!m_data) { |
| | outInfo->Set(vtkDataObject::DATA_OBJECT(), vtkUnstructuredGrid::New()); |
| | return 1; |
| | } |
| |
|
| | if (!m_data->IsA("vtkMultiBlockDataSet")) { |
| | |
| | outInfo->Set(vtkDataObject::DATA_OBJECT(), m_data); |
| | return 1; |
| | } |
| |
|
| | vtkSmartPointer<vtkMultiBlockDataSet> multiblock = vtkMultiBlockDataSet::SafeDownCast(m_data); |
| | |
| | unsigned long idx = 0; |
| | if (outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP())) { |
| | auto time = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()); |
| | auto frames = getFrameValues(); |
| |
|
| | |
| | |
| | for (auto& frame : frames) { |
| | frame = std::abs(frame - time); |
| | } |
| |
|
| | auto it = std::ranges::min_element(frames); |
| | idx = std::distance(frames.begin(), it); |
| | } |
| |
|
| | auto block = multiblock->GetBlock(idx); |
| | output->ShallowCopy(block); |
| | return 1; |
| | } |
| |
|