Conversation
| def _is_native_object(self, obj): | ||
| """Check if object is a native format object (OpenVDB grid, MRC object). | ||
|
|
||
| Parameters | ||
| ---------- | ||
| obj : object | ||
| Object to check | ||
|
|
||
| Returns | ||
| ------- | ||
| bool | ||
| True if obj is a native format object | ||
| """ | ||
| if vdb is not None and isinstance(obj, vdb.GridBase): | ||
| return True | ||
|
|
||
| return False | ||
|
|
||
| def _load_from_native(self, obj): | ||
| """Load Grid from a native format object. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| obj : object | ||
| Native format object (openvdb.GridBase, mrcfile.mrcfile.MrcFile, etc.) | ||
|
|
||
| """ | ||
| self.vdb_field = OpenVDB.OpenVDBField(grid=obj) | ||
|
|
||
| origin = self.vdb_field.origin | ||
| delta = self.vdb_field.delta | ||
| grid = self.vdb_field.grid | ||
|
|
||
| self.metadata = self.vdb_field.metadata | ||
| self._from_native_vdb = True | ||
|
|
||
| self._load(grid=grid, origin=origin, delta=delta) |
There was a problem hiding this comment.
This is currently too specific to VDB. Just leave out the native loading and focus on the convert_to.
| formats = ("mrc", "vdb") | ||
| if format_specifier.lower() == formats[1]: | ||
| grid_name = self.metadata.get("name", "density") | ||
| vdb_field = OpenVDB.OpenVDBField( | ||
| grid=self.grid, | ||
| origin=self.origin, | ||
| delta=self.delta, | ||
| name=grid_name, | ||
| tolerance=tolerance, | ||
| metadata=self.metadata, | ||
| ) | ||
|
|
||
| return vdb_field.vdb_grid |
There was a problem hiding this comment.
This is too clunky. Can we do something like
class Grid:
converter = {'MRC': mrc.MRC.from_grid,
'VDB': OpenVDB.OpenVDBField.from_grid,
'DX': OpenDX.field.from_grid,
}I am going to comment more extensively on #161
|
Can you have a look at #161 (comment) and let me know what you think? The idea is to first implement convert_to without OpenVDB (just for DX and MRC) and then add support for OpenVDB. |
Yep I looked into it and understood it. Just need to implement from_grid() and a native() inside OpenVDB.py. I will set it mrc and dx to none for now and do the OpenVDB. and improve the _export_vdb using from_grid() and also convert_to() using from_grid() and native() |
|
The idea is to first implement the API without OpenVDB (separate PR). Once that PR is merged, come back to OpenVDB. Do you want to do this work? |
|
Yep this can be done. |
This PR is related to #148 PR.
In this I have tried to fix #161 and #160 , only regarding
openvdb.Here are the changes-
__init__we check if given grid is native or not, and depending on it we define self.vdb_gridOpenVDB.py,_extract_from_vdb_gridis made to extract origin, delta and grid from given native object@orbeckst pls check!