Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions ScaFFold/datagen/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from pathlib import Path

import numpy as np
import open3d
from mpi4py import MPI

from ScaFFold.datagen.generate_fractal_points import generate_fractal_points
Expand Down Expand Up @@ -170,33 +169,18 @@ def main(config: Config):
# Generate points
points = generate_single_instance(config.point_num, params)

# Force point_data to be contiguous -- prevents possible segfaults in later Vector3dVector call from non-contiguous arrays
# Force point_data to be contiguous
points_contiguous = np.ascontiguousarray(points, dtype=DEFAULT_NP_DTYPE)

# Create o3d PointCloud object
pointcloud = open3d.geometry.PointCloud()

# Populate PointCloud points attribute with point_data
pointcloud.points = open3d.utility.Vector3dVector(points_contiguous)

# Construct the long path and short filename
# Construct the output path
out_dir = Path(instance_write_dir) / f"{category:06d}"
filename = f"{category:06d}_{instance:04d}.ply"
filename = f"{category:06d}_{instance:04d}.npy"

# Ensure parent directory exists
out_dir.mkdir(parents=True, exist_ok=True)

# Save current working directory so we can restore it later
cwd = os.getcwd()
try:
# Change to the output directory
os.chdir(out_dir)

# Write with short relative path
open3d.io.write_point_cloud(filename, pointcloud)
finally:
# Always restore the working directory
os.chdir(cwd)
# Save array to out_dir
np.save(out_dir / filename, points_contiguous)

end_time = time.time()
total_time = end_time - start_time
Expand Down
12 changes: 5 additions & 7 deletions ScaFFold/datagen/volumegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,18 @@
from typing import Dict

import numpy as np
import open3d as o3d
from mpi4py import MPI

from ScaFFold.utils.config_utils import Config

DEFAULT_NP_DTYPE = np.float64


def load_ply_with_open3d(path: str) -> np.ndarray:
def load_np_ptcloud(path: str) -> np.ndarray:
"""
Read a .ply via Open3D and return an (N,3) array of dtype float64.
Read a .npy file and return an (N,3) array of dtype float64.
"""
pcd = o3d.io.read_point_cloud(path)
pts = np.asarray(pcd.points)
pts = np.load(path)
return pts.astype(DEFAULT_NP_DTYPE, copy=False)


Expand Down Expand Up @@ -204,7 +202,7 @@ def main(config: Dict):
"fractals",
instances_dir,
f"{curr_category:06d}",
f"{curr_category:06d}_{curr_instance:04d}.ply",
f"{curr_category:06d}_{curr_instance:04d}.npy",
)

if not os.path.exists(point_cloud_path):
Expand All @@ -213,7 +211,7 @@ def main(config: Dict):
)
sys.exit(1)

points = load_ply_with_open3d(point_cloud_path)
points = load_np_ptcloud(point_cloud_path)
mask3d = points_to_voxelgrid(points, grid_size)

assert mask3d.shape == volume.shape[:3], (
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ dependencies = [
"numba>=0.60.0",
"tqdm>=4.67.1",
"wandb>=0.19.6",
"open3d>=0.18.0",
"PyYAML>=6.0.2",
"distconv @ git+https://github.com/LBANN/DistConv.git@232cba6",
]
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ numpy>=1.26.4
numba>=0.60.0
tqdm>=4.67.1
wandb>=0.19.6
open3d>=0.18.0
PyYAML>=6.0.2
mpi4py==4.1.1 --no-binary mpi4py
distconv @ git+https://github.com/LBANN/DistConv.git@232cba6