Multi VTK viewing/support (MoFEM)

About the development of the FEM module/workbench.

Moderator: bernd

Post Reply
Helios113
Posts: 27
Joined: Mon Jun 07, 2021 7:30 pm

Multi VTK viewing/support (MoFEM)

Post by Helios113 »

Hello,

I wanted to ask about multi VTK support in FreeCAD.

I looked through a few examples and I saw that the way this is handled now is by creating multiple FemPostPipeLine objects. Then to those one can apply different filters.

If I make changes to this pipeline to support multiple VTKs in one object will that be acceptable for a PR or should I make a new pipeline, say FemMultiPostPipeline which is exclusively targeted for multi VTK support?

The way I plan on implementing the multi VTKs currently is by simply creating a std::vector and pushing the m_dataObject s when they are read in PropertyPostDataObject.

Code: Select all

//PropertyPostDataObject.h
protected:
    void createDataObjectByExternalType(vtkSmartPointer<vtkDataObject> ex);
    vtkSmartPointer<vtkDataObject> m_dataObject;
    std::vector<vtkSmartPointer<vtkDataObject>> data_vector;
};

Code: Select all

//PropertyPostDataObject.cpp
if(ds) {
        createDataObjectByExternalType(ds);
        m_dataObject->DeepCopy(ds);
        try{
            data_vector.push_back(m_dataObject);
        }
        catch (...){
            Base::Console().Message("We failed at push back");
        }
The getValue function will be amended to return the current "frame" of the new vector, so if legacy code doesn't know about the multi vtk support the frame will always be zero hence to other parts of FreeCAD it will look exactly the same as before.

Code: Select all

//PropertyPostDataObject.cpp
const vtkSmartPointer<vtkDataObject>& PropertyMultiPostDataObject::getValue(void)const
{
    return data_vector.at(frame);
}
Obviously there is more to it than the snippets above, the main issue in my mind is what the code structure should be.
Either way, any thoughts or advice from people familiar with the VTK input?

Regards,
Preslav
Helios113
Posts: 27
Joined: Mon Jun 07, 2021 7:30 pm

Re: Multi VTK viewing/support (MoFEM)

Post by Helios113 »

Ok, so from a day of testing I figured out that modifying the existing framework will lead to a lot of head aches.
I think there are still ways to do it and it is a good learning experience, because even if it is ultimately a bad idea, I can use the knowledge to create the new objects in a jiffy.

I saw that this post has been viewed a few times but with no replies sadly :cry:
Any input is amazing, and I am happy to hear what everyone thinks or explain what I am doing.

Finally, is there a way to ping bernd, to ask for info and advice?
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Multi VTK viewing/support (MoFEM)

Post by Kunda1 »

bernd wrote: pinged by pinger macro
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Postprocessing pipeline, clipping plane

Post by bernd »

ickby wrote: ping
Helios113
Posts: 27
Joined: Mon Jun 07, 2021 7:30 pm

Re: Multi VTK viewing/support (MoFEM)

Post by Helios113 »

So I have this working very crudely at the moment. Here is a screen shot of how it looks:
Screenshot from 2021-09-03 10-15-14.png
Screenshot from 2021-09-03 10-15-14.png (180.7 KiB) Viewed 1936 times



I can change between the 6 frames in this example and render displacements. Filters don't work properly yet, but I will tackle than soon.
This was done modifying the existing post objects.

What do you think would be the best/proper way to implement this?

ickby wrote: ping
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: Multi VTK viewing/support (MoFEM)

Post by ickby »

Nice, I'm always glad people work on the VTK stuff! For the proposal I think we should think careful about how to implement that, as there are two possible things to consider:

1. The vtk datastructure does allow for multiple datasets in one result. This is used e.g. for time analysis, one dataset for each timestep, or frequency analysis, one dataset for each mode shape. This is not implemented in FreeCADs viewer yet but could be relevant in many ways

2. To have multiple results by different analysis, I think this is what you try to do.

So for me the question becomes what implementation is most intuitive for the user, assuming that both possibilities are implemented for FreeCAD in the future. I personally think the first version (multi datasets in one file) need to be integrated into the pipeline, and all filters, something close to what paraview does (It would be a additional pane in the task view for that choice, the same for pipeline and filters). So adding annother dimension of multiple result files seem very hard to grasp, as worst case you get multiple results each with multiple datasets... thats somewhat complicated. Hence my original idea was to give each result it's own pipeline, and implement a system that let's you easily copy a set of filters from one pipeline to another.

But one could also think a dfferently and more towards your idea, I see that definitely valid. But than it must be very clear to the user what to choose where, and how things connect. I would not call it Frame, as its completely unclear in its meaning. I would make a new pane above the "Result display options" which maybe called "Result selection". I would also not use the show button, but add "Apply" to the task buttons, the same way all filter work (including auto apply if selected). Than there should be a option in the FEM workbench next to "crreate pipeline from result" called "add result to existing pipeline". I would assume this makes it intuitive.

A third option would simply be to implement the mutli-dataset option of VTK files, and you to use it. So basically giving the user the option to add a result as a dataset within the existing result. That would implement a generally needed feature and you could easily use it.

Sorry for being somewhat unconcrete, but I'm trying to think out loud :)
Helios113
Posts: 27
Joined: Mon Jun 07, 2021 7:30 pm

Re: Multi VTK viewing/support (MoFEM)

Post by Helios113 »

Hello,

I think you misunderstood what I am trying to achieve, or more probably I just explained it very poorly :( . I am exactly trying to implement multiple datasets in one result object (Option 1). I just wanted to do this without disturbing the code too much, because I am unsure what the (main) FreeCAD team wants. Hence, the code I posted attempts to implement multiple datasets, where each data set is a separate .vtk file rather than one composite file. Something like this for example (vtk results):
Archive.zip
(656.36 KiB) Downloaded 54 times
The option you described, where one file contains multiple results is basically a wrapper file that points again to multiple .vtk's so it will be necessary to have a multi vtk structure either way.

In my current attempt, what I thought might be nice, is to have the vtk switch happen in PropertyPostDataObject so that the filter script doesn't know that a switch happened. This way, you have one post pipeline object which contains all analysis steps (whether one composite file or multiple vtks) and any filter that is applied to this object gets updated on whatever "frame" (time step, frequency) you choose.

I am running into issues here and there, and I am basically looking for advice from someone if you are up for it :).

For example, I don't know if I should make a new pipeline for non-linear analyses(multi dataset) or should I modify the current one to handle both cases?

Regards,
Preslav
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: Multi VTK viewing/support (MoFEM)

Post by ickby »

Ah good to be aligned :)
The option you described, where one file contains multiple results is basically a wrapper file that points again to multiple .vtk's so it will be necessary to have a multi vtk structure either way.
To be honest, I'm very rusty with the VTK API, and was not very good to begin with. But I thougth that such multi data sets are imported as a normal vtkDataObject, but than as a subclass of "vtkCompositeDataSet" (like vtkTemporalDataSet for time data). So my idea was to keep the FreeCAD data property as is, with just the single vtkDataObject, but inspect this object a bit closer to check if blocks or piece or time data is in there. When such data is detected, just give the user more options to choose. Like having a pane for blocks, and a pane for time data in the filter and pipeline task dialog, which are filled when the data is available.
If this is not the case than the property needs to change to multile vtk objects stored, yes. But I think this would be the worse option, as there are vtk filters which can work on CompositeDataSets. If we use our own structure we cannot really use those filters later on, which would be a shame. Also in case of time you only want to display one at a time, but for blocks and pieces you want to be able to display many. So we should try to get the data into a single vtkDataObject.
I am running into issues here and there, and I am basically looking for advice from someone if you are up for it :).
I'm glad to help if it improves the postprocessing :)
For example, I don't know if I should make a new pipeline for non-linear analyses(multi dataset) or should I modify the current one to handle both cases?
Imho there should be only one, and this should be flexible as possible to handle all cases. Reason for that is, that FreeCAD uses multiple solvers with all kind of output, often vtk directly, and it would be a shame if the postprocessing is specific for special cases only.
Post Reply