You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nmWTAI-Platform/Src/nmNum/nmData/nmPebiResultSnapshotRenderA...

129 lines
3.3 KiB
C++

#include "nmPebiResultSnapshotRenderAdapter.h"
#include <vtkAlgorithmOutput.h>
#include <vtkCellData.h>
#include <vtkDoubleArray.h>
#include <vtkTrivialProducer.h>
#include <vtkUnstructuredGrid.h>
nmPebiResultSnapshotRenderAdapter::nmPebiResultSnapshotRenderAdapter()
: m_pRenderGrid(vtkSmartPointer<vtkUnstructuredGrid>::New()),
m_pPressureBuffer(vtkSmartPointer<vtkDoubleArray>::New()),
m_pProducer(vtkSmartPointer<vtkTrivialProducer>::New()),
m_eBindingMode(SharedPressureFrame),
m_nCurrentFrameIndex(-1)
{
}
nmPebiResultSnapshotRenderAdapter::~nmPebiResultSnapshotRenderAdapter()
{
clear();
}
bool nmPebiResultSnapshotRenderAdapter::initialize(
const QSharedPointer<const nmPebiResultSnapshot>& pSnapshot,
PressureBindingMode eBindingMode)
{
clear();
if(pSnapshot.isNull() || !pSnapshot->isComplete() ||
(eBindingMode != SharedPressureFrame &&
eBindingMode != CopiedPressureFrame))
{
return false;
}
m_pSnapshot = pSnapshot;
m_eBindingMode = eBindingMode;
if(!m_pSnapshot->copyResultGridStructure(m_pRenderGrid))
{
clear();
return false;
}
// TrivialProducer 只负责把适配器网格接入管道,不会主动修改输出对象。
m_pProducer->SetOutput(m_pRenderGrid);
m_pProducer->Modified();
return true;
}
void nmPebiResultSnapshotRenderAdapter::clear()
{
// 先断开管道和 CellData及时释放对旧快照压力数组的临时 VTK 引用。
if(m_pProducer != NULL)
{
m_pProducer->SetOutput(NULL);
m_pProducer->Modified();
}
if(m_pRenderGrid != NULL)
{
m_pRenderGrid->GetCellData()->Initialize();
m_pRenderGrid->Initialize();
}
if(m_pPressureBuffer != NULL)
{
m_pPressureBuffer->Initialize();
}
m_pSnapshot.clear();
m_eBindingMode = SharedPressureFrame;
m_nCurrentFrameIndex = -1;
}
bool nmPebiResultSnapshotRenderAdapter::setPressureFrame(int nFrameIndex)
{
if(m_pSnapshot.isNull() || m_pRenderGrid == NULL ||
nFrameIndex < 0 ||
nFrameIndex >= m_pSnapshot->getPressureFrameCount())
{
return false;
}
bool bBound = false;
if(m_eBindingMode == SharedPressureFrame)
{
bBound = m_pSnapshot->bindPressureFrame(
nFrameIndex, m_pRenderGrid);
}
else
{
bBound = m_pSnapshot->copyPressureFrame(
nFrameIndex, m_pPressureBuffer);
if(bBound)
{
m_pRenderGrid->GetCellData()->SetScalars(m_pPressureBuffer);
m_pRenderGrid->Modified();
}
}
if(!bBound)
{
return false;
}
m_nCurrentFrameIndex = nFrameIndex;
m_pProducer->Modified();
return true;
}
vtkAlgorithmOutput*
nmPebiResultSnapshotRenderAdapter::getOutputPort() const
{
return m_pSnapshot.isNull() || m_pProducer == NULL
? NULL : m_pProducer->GetOutputPort();
}
int nmPebiResultSnapshotRenderAdapter::getCurrentFrameIndex() const
{
return m_nCurrentFrameIndex;
}
vtkIdType nmPebiResultSnapshotRenderAdapter::getCellCount() const
{
return m_pRenderGrid == NULL ? 0 :
m_pRenderGrid->GetNumberOfCells();
}
bool nmPebiResultSnapshotRenderAdapter::isUsingSharedPressure() const
{
return !m_pSnapshot.isNull() &&
m_eBindingMode == SharedPressureFrame;
}