Skip to content

Commit

Permalink
added Particle primitive wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ncsaba committed Feb 19, 2014
1 parent e5f30ae commit 772a992
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
3 changes: 2 additions & 1 deletion brlcad/primitives/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
from torus import Torus, ETO
from epa import EPA, EHY
from hyperboloid import Hyperboloid
from particle import Particle

__all__ = [
"Primitive", "ARB8", "ARBN", "Ellipsoid", "Sphere", "RPC", "RHC",
"Primitive", "ARB8", "ARBN", "Ellipsoid", "Sphere", "RPC", "RHC", "Particle",
"TGC", "Cone", "RCC", "TRC", "Torus", "ETO", "EPA", "EHY", "Hyperboloid",
"Combination", "negate", "intersect", "subtract", "union", "xor", "wrap_tree", "leaf"
]
39 changes: 39 additions & 0 deletions brlcad/primitives/particle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Python wrapper for the Particle primitive of BRL-CAD.
"""

from base import Primitive
from brlcad.vmath import Vector


class Particle(Primitive):

def __init__(self, name, base=(0, 0, 0), height=(0, 0, 1), r_base=0.5, r_end=0.2, copy=False):
Primitive.__init__(self, name=name)
self.base = Vector(base, copy=copy)
self.height = Vector(height, copy=copy)
self.r_base = r_base
self.r_end = r_end

def __repr__(self):
return "{}({}, base={}, height={}, r_base={}, r_end={})".format(
self.__class__.__name__, self.name, repr(self.base), repr(self.height), self.r_base, self.r_end
)

def update_params(self, params):
params.update({
"base": self.base,
"height": self.height,
"r_base": self.r_base,
"r_end": self.r_end,
})

@staticmethod
def from_wdb(name, data):
return Particle(
name=name,
base=data.part_V,
height=data.part_H,
r_base=data.part_vrad,
r_end=data.part_hrad,
)
3 changes: 2 additions & 1 deletion brlcad/primitives/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from epa import EPA, EHY
from combination import Combination
from hyperboloid import Hyperboloid
from particle import Particle


MAGIC_TO_PRIMITIVE_TYPE = {
Expand Down Expand Up @@ -42,7 +43,7 @@
librt.ID_BSPLINE: ("NURB", Primitive, librt.RT_NURB_INTERNAL_MAGIC, librt.struct_rt_nurb_internal),
librt.ID_POLY: ("PG", Primitive, librt.RT_PG_INTERNAL_MAGIC, librt.struct_rt_pg_internal),
librt.ID_PIPE: ("PIPE", Primitive, librt.RT_PIPE_INTERNAL_MAGIC, librt.struct_rt_pipe_internal),
librt.ID_PARTICLE: ("PARTICLE", Primitive, librt.RT_PART_INTERNAL_MAGIC, librt.struct_rt_part_internal),
librt.ID_PARTICLE: ("PARTICLE", Particle, librt.RT_PART_INTERNAL_MAGIC, librt.struct_rt_part_internal),
librt.ID_REVOLVE: ("REVOLVE", Primitive, librt.RT_REVOLVE_INTERNAL_MAGIC, librt.struct_rt_revolve_internal),
librt.ID_RHC: ("RHC", RHC, librt.RT_RHC_INTERNAL_MAGIC, librt.struct_rt_rhc_internal),
librt.ID_RPC: ("RPC", RPC, librt.RT_RPC_INTERNAL_MAGIC, librt.struct_rt_rpc_internal),
Expand Down
6 changes: 3 additions & 3 deletions brlcad/wdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ def arbn(self, name, planes=(1, 0, 0, 1, -1, 0, 0, 1, 0, 1, 0, 1, 0, -1, 0, 1, 0
planes_arg = cta.brlcad_copy(cta.planes(planes), "mk_arbn")
libwdb.mk_arbn(self.db_fp, name, len(planes_arg)/4, planes_arg)

@mk_wrap_primitive(primitives.Primitive)
def particle(self, name, base=(0, 0, 0), v_end=(0, 0, 1), r_base=0.5, r_end=0.2):
libwdb.mk_particle(self.db_fp, name, cta.points(base), cta.direction(v_end), r_base, r_end)
@mk_wrap_primitive(primitives.Particle)
def particle(self, name, base=(0, 0, 0), height=(0, 0, 1), r_base=0.5, r_end=0.2):
libwdb.mk_particle(self.db_fp, name, cta.points(base), cta.direction(height), r_base, r_end)

@mk_wrap_primitive(primitives.Primitive)
def pipe(self, name, segments=(((0, 0, 0), 0.5, 0.3, 1), ((0, 0, 1), 0.5, 0.3, 1))):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_wdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ def test_defaults(self):
self.assertTrue(shape.a_vec.is_same((0, 1, 0)))
self.assertEqual(0.5, shape.b_mag)
self.assertEqual(0.2, shape.base_neck_ratio)
shape = brl_db.lookup_internal("particle.s")
self.assertTrue(shape.base.is_same((0, 0, 0)))
self.assertTrue(shape.height.is_same((0, 0, 1)))
self.assertEqual(0.5, shape.r_base)
self.assertEqual(0.2, shape.r_end)


if __name__ == "__main__":
Expand Down

0 comments on commit 772a992

Please sign in to comment.