Skip to content

Commit

Permalink
Implement object output
Browse files Browse the repository at this point in the history
  • Loading branch information
sethrj committed Mar 5, 2024
1 parent 9dee003 commit 1b2a97d
Show file tree
Hide file tree
Showing 15 changed files with 479 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/orange/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ if(CELERITAS_USE_JSON)
OrangeInputIO.json.cc
detail/OrangeInputIOImpl.json.cc
orangeinp/CsgTreeIO.json.cc
orangeinp/ObjectIO.json.cc
)
list(APPEND PRIVATE_DEPS nlohmann_json::nlohmann_json)
endif()
Expand Down
59 changes: 59 additions & 0 deletions src/orange/orangeinp/ConvexRegion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "corecel/Constants.hh"
#include "corecel/cont/Range.hh"
#include "corecel/io/JsonPimpl.hh"
#include "geocel/BoundingBox.hh"
#include "geocel/Types.hh"
#include "orange/surf/ConeAligned.hh"
Expand All @@ -21,6 +22,10 @@

#include "ConvexSurfaceBuilder.hh"

#if CELERITAS_USE_JSON
# include "ObjectIO.json.hh"
#endif

namespace celeritas
{
namespace orangeinp
Expand Down Expand Up @@ -75,6 +80,15 @@ void Box::build(ConvexSurfaceBuilder& insert_surface) const
insert_surface(Sense::inside, PlaneZ{hw_[Z]});
}

//---------------------------------------------------------------------------//
/*!
* Write output to the given JSON object.
*/
void Box::output(JsonPimpl* j) const
{
to_json_pimpl(j, *this);
}

//---------------------------------------------------------------------------//
// CONE
//---------------------------------------------------------------------------//
Expand Down Expand Up @@ -167,6 +181,15 @@ void Cone::build(ConvexSurfaceBuilder& insert_surface) const
insert_surface(Sense::outside, interior_bbox);
}

//---------------------------------------------------------------------------//
/*!
* Write output to the given JSON object.
*/
void Cone::output(JsonPimpl* j) const
{
to_json_pimpl(j, *this);
}

//---------------------------------------------------------------------------//
// CYLINDER
//---------------------------------------------------------------------------//
Expand All @@ -191,6 +214,15 @@ void Cylinder::build(ConvexSurfaceBuilder& insert_surface) const
insert_surface(CCylZ{radius_});
}

//---------------------------------------------------------------------------//
/*!
* Write output to the given JSON object.
*/
void Cylinder::output(JsonPimpl* j) const
{
to_json_pimpl(j, *this);
}

//---------------------------------------------------------------------------//
// ELLIPSOID
//---------------------------------------------------------------------------//
Expand Down Expand Up @@ -249,6 +281,15 @@ void Ellipsoid::build(ConvexSurfaceBuilder& insert_surface) const
insert_surface(Sense::outside, BBox{-inner_radii, inner_radii});
}

//---------------------------------------------------------------------------//
/*!
* Write output to the given JSON object.
*/
void Ellipsoid::output(JsonPimpl* j) const
{
to_json_pimpl(j, *this);
}

//---------------------------------------------------------------------------//
// PRISM
//---------------------------------------------------------------------------//
Expand Down Expand Up @@ -319,6 +360,15 @@ void Prism::build(ConvexSurfaceBuilder& insert_surface) const
insert_surface(Sense::outside, interior_bbox);
}

//---------------------------------------------------------------------------//
/*!
* Write output to the given JSON object.
*/
void Prism::output(JsonPimpl* j) const
{
to_json_pimpl(j, *this);
}

//---------------------------------------------------------------------------//
// SPHERE
//---------------------------------------------------------------------------//
Expand All @@ -339,6 +389,15 @@ void Sphere::build(ConvexSurfaceBuilder& insert_surface) const
insert_surface(SphereCentered{radius_});
}

//---------------------------------------------------------------------------//
/*!
* Write output to the given JSON object.
*/
void Sphere::output(JsonPimpl* j) const
{
to_json_pimpl(j, *this);
}

//---------------------------------------------------------------------------//
} // namespace orangeinp
} // namespace celeritas
23 changes: 23 additions & 0 deletions src/orange/orangeinp/ConvexRegion.hh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

namespace celeritas
{
struct JsonPimpl;

namespace orangeinp
{
class ConvexSurfaceBuilder;
Expand Down Expand Up @@ -43,6 +45,9 @@ class ConvexRegionInterface
//! Construct surfaces that are AND-ed into this region
virtual void build(ConvexSurfaceBuilder&) const = 0;

//! Write the region to a JSON object
virtual void output(JsonPimpl*) const = 0;

protected:
//!@{
//! Allow construction and assignment only through daughter classes
Expand All @@ -65,6 +70,9 @@ class Box final : public ConvexRegionInterface
// Build surfaces
void build(ConvexSurfaceBuilder&) const final;

// Output to JSON
void output(JsonPimpl*) const final;

//// ACCESSORS ////

//! Half-width for each axis
Expand Down Expand Up @@ -105,6 +113,9 @@ class Cone final : public ConvexRegionInterface
// Build surfaces
void build(ConvexSurfaceBuilder&) const final;

// Output to JSON
void output(JsonPimpl*) const final;

//// ACCESSORS ////

//! Lower and upper radii
Expand All @@ -131,6 +142,9 @@ class Cylinder final : public ConvexRegionInterface
// Build surfaces
void build(ConvexSurfaceBuilder&) const final;

// Output to JSON
void output(JsonPimpl*) const final;

//// ACCESSORS ////

//! Radius
Expand All @@ -157,6 +171,9 @@ class Ellipsoid final : public ConvexRegionInterface
// Build surfaces
void build(ConvexSurfaceBuilder&) const final;

// Output to JSON
void output(JsonPimpl*) const final;

//// ACCESSORS ////

//! Radius along each axis
Expand Down Expand Up @@ -197,6 +214,9 @@ class Prism final : public ConvexRegionInterface
// Build surfaces
void build(ConvexSurfaceBuilder&) const final;

// Output to JSON
void output(JsonPimpl*) const final;

//// ACCESSORS ////

//! Number of sides
Expand Down Expand Up @@ -235,6 +255,9 @@ class Sphere final : public ConvexRegionInterface
// Build surfaces
void build(ConvexSurfaceBuilder&) const final;

// Output to JSON
void output(JsonPimpl*) const final;

//// ACCESSORS ////

//! Radius
Expand Down
25 changes: 25 additions & 0 deletions src/orange/orangeinp/CsgObject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@

#include <utility>

#include "corecel/io/JsonPimpl.hh"

#include "detail/CsgUnitBuilder.hh"
#include "detail/VolumeBuilder.hh"

#if CELERITAS_USE_JSON
# include "ObjectIO.json.hh"
#endif

namespace celeritas
{
namespace orangeinp
Expand Down Expand Up @@ -49,6 +55,15 @@ NodeId NegatedObject::build(VolumeBuilder& vb) const
return vb.insert_region(Label{label_}, Negated{daughter_id});
}

//---------------------------------------------------------------------------//
/*!
* Output to JSON.
*/
void NegatedObject::output(JsonPimpl* j) const
{
to_json_pimpl(j, *this);
}

//---------------------------------------------------------------------------//
// JOIN_OBJECTS
//---------------------------------------------------------------------------//
Expand Down Expand Up @@ -91,6 +106,16 @@ NodeId JoinObjects<Op>::build(VolumeBuilder& vb) const
return vb.insert_region(Label{label_}, Joined{op_token, std::move(nodes)});
}

//---------------------------------------------------------------------------//
/*!
* Output to JSON.
*/
template<OperatorToken Op>
void JoinObjects<Op>::output(JsonPimpl* j) const
{
to_json_pimpl(j, *this);
}

//---------------------------------------------------------------------------//
// FREE FUNCTIONS
//---------------------------------------------------------------------------//
Expand Down
6 changes: 6 additions & 0 deletions src/orange/orangeinp/CsgObject.hh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class NegatedObject : public ObjectInterface
// Construct a volume from this object
NodeId build(VolumeBuilder&) const final;

// Write the object to JSON
void output(JsonPimpl*) const final;

private:
std::string label_;
SPConstObject obj_;
Expand Down Expand Up @@ -75,6 +78,9 @@ class JoinObjects : public ObjectInterface
// Construct a volume from this object
NodeId build(VolumeBuilder&) const final;

// Write the object to JSON
void output(JsonPimpl*) const final;

private:
std::string label_;
VecObject objects_;
Expand Down
Loading

0 comments on commit 1b2a97d

Please sign in to comment.