Fem: add a scale() function to FemPostPipeline

This commit is contained in:
wmayer
2022-04-15 12:08:47 +02:00
parent e9e04221c4
commit f00a3f59c4
6 changed files with 73 additions and 1 deletions

View File

@@ -149,6 +149,11 @@ void FemPostPipeline::read(Base::FileInfo File) {
throw Base::FileException("Unknown extension");
}
void FemPostPipeline::scale(double s)
{
Data.scale(s);
}
void FemPostPipeline::onChanged(const Property* prop)
{
if (prop == &Filter || prop == &Mode) {

View File

@@ -58,6 +58,7 @@ public:
//load data from files
static bool canRead(Base::FileInfo file);
void read(Base::FileInfo file);
void scale(double s);
//load from results
void load(FemResultObject* res);

View File

@@ -18,6 +18,11 @@
<UserDocu>Read in vtk file</UserDocu>
</Documentation>
</Methode>
<Methode Name="scale">
<Documentation>
<UserDocu>scale the points of a loaded vtk file</UserDocu>
</Documentation>
</Methode>
<Methode Name="load">
<Documentation>
<UserDocu>Load a result object</UserDocu>

View File

@@ -51,6 +51,16 @@ PyObject* FemPostPipelinePy::read(PyObject *args)
return nullptr;
}
PyObject* FemPostPipelinePy::scale(PyObject *args)
{
double scale;
if (PyArg_ParseTuple(args, "d", &scale)) {
getFemPostPipelinePtr()->scale(scale);
Py_Return;
}
return nullptr;
}
PyObject* FemPostPipelinePy::load(PyObject *args)
{
PyObject* py;

View File

@@ -67,6 +67,51 @@ PropertyPostDataObject::~PropertyPostDataObject()
{
}
void PropertyPostDataObject::scaleDataObject(vtkDataObject* dataObject, double s)
{
auto scalePoints = [](vtkPoints* points, double s) {
for (vtkIdType i = 0; i < points->GetNumberOfPoints(); i++) {
double xyz[3];
points->GetPoint(i, xyz);
for (int j = 0; j < 3; j++)
xyz[j] *= s;
points->SetPoint(i, xyz);
}
};
if (dataObject->GetDataObjectType() == VTK_POLY_DATA) {
vtkPolyData* dataSet = vtkPolyData::SafeDownCast(dataObject);
scalePoints(dataSet->GetPoints(), s);
}
else if (dataObject->GetDataObjectType() == VTK_STRUCTURED_GRID) {
vtkStructuredGrid* dataSet = vtkStructuredGrid::SafeDownCast(dataObject);
scalePoints(dataSet->GetPoints(), s);
}
else if (dataObject->GetDataObjectType() == VTK_UNSTRUCTURED_GRID) {
vtkUnstructuredGrid* dataSet = vtkUnstructuredGrid::SafeDownCast(dataObject);
scalePoints(dataSet->GetPoints(), s);
}
else if (dataObject->GetDataObjectType() == VTK_MULTIBLOCK_DATA_SET) {
vtkMultiBlockDataSet* dataSet = vtkMultiBlockDataSet::SafeDownCast(dataObject);
for (unsigned int i = 0; i < dataSet->GetNumberOfBlocks(); i++)
scaleDataObject(dataSet->GetBlock(i), s);
}
else if (dataObject->GetDataObjectType() == VTK_MULTIPIECE_DATA_SET) {
vtkMultiPieceDataSet* dataSet = vtkMultiPieceDataSet::SafeDownCast(dataObject);
for (unsigned int i = 0; i < dataSet->GetNumberOfPieces(); i++)
scaleDataObject(dataSet->GetPiece(i), s);
}
}
void PropertyPostDataObject::scale(double s)
{
if (m_dataObject) {
aboutToSetValue();
scaleDataObject(m_dataObject, s);
hasSetValue();
}
}
void PropertyPostDataObject::setValue(const vtkSmartPointer<vtkDataObject>& ds)
{
aboutToSetValue();
@@ -75,8 +120,9 @@ void PropertyPostDataObject::setValue(const vtkSmartPointer<vtkDataObject>& ds)
createDataObjectByExternalType(ds);
m_dataObject->DeepCopy(ds);
}
else
else {
m_dataObject = nullptr;
}
hasSetValue();
}

View File

@@ -47,6 +47,8 @@ public:
/** @name Getter/setter */
//@{
/// Scale the point coordinates of the data set with factor \a s
void scale(double s);
/// set the dataset
void setValue(const vtkSmartPointer<vtkDataObject>&);
/// get the part shape
@@ -79,6 +81,9 @@ public:
/// Get valid paths for this property; used by auto completer
virtual void getPaths(std::vector<App::ObjectIdentifier> & paths) const;
private:
static void scaleDataObject(vtkDataObject*, double s);
protected:
void createDataObjectByExternalType(vtkSmartPointer<vtkDataObject> ex);
vtkSmartPointer<vtkDataObject> m_dataObject;