-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PoC / Paraview integration for mesh_doctor #16
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from paraview.util.vtkAlgorithm import * | ||
from paraview.selection import * | ||
from checks import element_volumes | ||
|
||
|
||
@smproxy.filter(name="Mesh Doctor(GEOS)") | ||
@smproperty.input(name="Input") | ||
@smdomain.datatype(dataTypes=["vtkUnstructuredGrid"], composite_data_supported=False) | ||
class ElementVolumesFilter(VTKPythonAlgorithmBase): | ||
""" | ||
Example portage meshDoctor in PV Python plugins | ||
""" | ||
def __init__(self): | ||
super().__init__(outputType='vtkUnstructuredGrid') | ||
self.opt = element_volumes.Options(0) | ||
|
||
def RequestData(self, request, inInfo, outInfo): | ||
inData = self.GetInputData(inInfo, 0, 0) | ||
outData = self.GetOutputData(outInfo, 0) | ||
assert inData is not None | ||
if outData is None or (not outData.IsA(inData.GetClassName())): | ||
outData = inData.NewInstance() | ||
extracted = self._Process(inData) | ||
outData.DeepCopy( extracted.GetOutput() ) | ||
outInfo.GetInformationObject(0).Set(outData.DATA_OBJECT(), extracted.GetOutput()) | ||
|
||
print("1> There are {} cells under {} m3 vol".format(outData.GetNumberOfCells(), self.opt)) | ||
return 1 | ||
|
||
def _Process(self,mesh): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add type hints to your functions (if there's no problem with some python compatibility)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
from paraview.vtk import vtkIdTypeArray, vtkSelectionNode, vtkSelection, vtkCollection | ||
from vtk import vtkExtractSelection | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We usually try to put all the includes at the top of the file, not nested in functions. BTW, I'm surprised you have to gather There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed I was also suprised that it is missing and TBF jumped right to the closest working version from what I already had. I will try with |
||
res = element_volumes.check(mesh, self.opt) | ||
ids = vtkIdTypeArray() | ||
ids.SetNumberOfComponents(1) | ||
for val in res.element_volumes: | ||
ids.InsertNextValue(val[0]) | ||
|
||
|
||
selectionNode = vtkSelectionNode() | ||
selectionNode.SetFieldType(vtkSelectionNode.CELL) | ||
selectionNode.SetContentType(vtkSelectionNode.INDICES) | ||
selectionNode.SetSelectionList(ids) | ||
selection = vtkSelection() | ||
selection.AddNode(selectionNode) | ||
|
||
extracted = vtkExtractSelection() | ||
extracted.SetInputDataObject(0, mesh) | ||
extracted.SetInputData(1, selection) | ||
extracted.Update() | ||
print("There are {} cells under {} m3 vol".format(extracted.GetOutput().GetNumberOfCells(), self.opt)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use a logger instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will discard text printing as it is more of a debug tool for now |
||
print("There are {} arrays of cell data".format(extracted.GetOutput().GetCellData().GetNumberOfArrays(), self.opt)) | ||
|
||
return extracted | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to return the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I indeed only need to return a |
||
|
||
@smproperty.doublevector(name="Vol Threshold", default_values=["0.0"]) | ||
def SetValue(self, val): | ||
self.opt = element_volumes.Options(val) | ||
print("Settings value:", self.opt) | ||
self.Modified() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible, please be specific about what you include (i.e. no
*
)