PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
util::geometry::ComplexGeomObject Class Reference

Defines complex geometrical object. More...

#include <geomObjects.h>

Inheritance diagram for util::geometry::ComplexGeomObject:
Collaboration diagram for util::geometry::ComplexGeomObject:

Public Member Functions

 ComplexGeomObject ()
 Constructor.
 
 ComplexGeomObject (std::vector< std::shared_ptr< util::geometry::GeomObject > > &obj, std::vector< std::string > obj_flag, size_t dim, std::string description="")
 Constructor.
 
double volume () const override
 Computes the volume (area in 2d, length in 1d) of object.
 
util::Point center () const override
 Computes the center of object.
 
std::pair< util::Point, util::Pointbox () const override
 Computes the bounding box of object.
 
std::pair< util::Point, util::Pointbox (const double &tol) const override
 Computes the bounding box of object.
 
double inscribedRadius () const override
 Computes the radius of biggest circle/sphere completely within the object.
 
double boundingRadius () const override
 Computes the radius of smallest circle/sphere such that object can be fit into it.
 
std::string printStr (int nt, int lvl) const override
 Returns the string containing printable information about the object.
 
void print (int nt, int lvl) const override
 Prints the information about the object.
 
void print () const override
 Prints the information about the object.
 
Interaction with point
bool isInside (const util::Point &x) const override
 Checks if point is inside this object.
 
bool isOutside (const util::Point &x) const override
 Checks if point is outside of this object.
 
bool isNear (const util::Point &x, const double &tol) const override
 Checks if point is within given distance of this object.
 
bool isNearBoundary (const util::Point &x, const double &tol, const bool &within) const override
 cons
 
bool doesIntersect (const util::Point &x) const override
 Checks if point lies exactly on the boundary.
 
Interaction with box
bool isInside (const std::pair< util::Point, util::Point > &box) const override
 Checks if box is completely inside.
 
bool isOutside (const std::pair< util::Point, util::Point > &box) const override
 Checks if box is outside of the object.
 
bool isNear (const std::pair< util::Point, util::Point > &box, const double &tol) const override
 Checks if box is within given distance of this object.
 
bool doesIntersect (const std::pair< util::Point, util::Point > &box) const override
 Checks if box intersects this object.
 
- Public Member Functions inherited from util::geometry::GeomObject
 GeomObject (std::string name="", std::string description="")
 Constructor.
 

Data Fields

std::vector< std::shared_ptr< util::geometry::GeomObject > > d_obj
 Object.
 
std::vector< std::string > d_objFlag
 Object flag.
 
std::vector< intd_objFlagInt
 Object integer flags. Here, +1 means object is filling and -1 means object is void.
 
size_t d_dim
 Dimension objects live in.
 
- Data Fields inherited from util::geometry::GeomObject
const std::string d_name
 name of object
 
const std::string d_description
 Further description of object.
 
std::vector< std::string > d_tags
 Tags/attributes about the object.
 

Detailed Description

Defines complex geometrical object.

Definition at line 2559 of file geomObjects.h.

Constructor & Destructor Documentation

◆ ComplexGeomObject() [1/2]

util::geometry::ComplexGeomObject::ComplexGeomObject ( )
inline

Constructor.

Definition at line 2565 of file geomObjects.h.

2565: GeomObject("complex", ""), d_dim(0) {};
size_t d_dim
Dimension objects live in.
GeomObject(std::string name="", std::string description="")
Constructor.
Definition geomObjects.h:39

◆ ComplexGeomObject() [2/2]

util::geometry::ComplexGeomObject::ComplexGeomObject ( std::vector< std::shared_ptr< util::geometry::GeomObject > > &  obj,
std::vector< std::string >  obj_flag,
size_t  dim,
std::string  description = "" 
)
inline

Constructor.

Parameters
objVector of geometrical objects
obj_flagSpecifies which objects are filling and which are void
dimDimension of the composite object
descriptionDescription of object (e.g., further classification or any tag)

Definition at line 2575 of file geomObjects.h.

2579 : GeomObject("complex", description),
2580 d_obj(obj),
2582 d_dim(dim) {
2583
2584 for (const auto &s: d_objFlag)
2585 if (s == "plus")
2587 else if (s == "minus")
2588 d_objFlagInt.push_back(-1);
2589 else {
2590 std::cerr
2591 << "Error: Check object flag " + s +
2592 " passed to create ComplexGeomObject\n";
2593 exit(1);
2594 }
2595 };
std::vector< std::shared_ptr< util::geometry::GeomObject > > d_obj
Object.
std::vector< int > d_objFlagInt
Object integer flags. Here, +1 means object is filling and -1 means object is void.
std::vector< std::string > d_objFlag
Object flag.

References d_dim, d_objFlag, and d_objFlagInt.

Member Function Documentation

◆ boundingRadius()

double util::geometry::ComplexGeomObject::boundingRadius ( ) const
overridevirtual

Computes the radius of smallest circle/sphere such that object can be fit into it.

Returns
Radius Radius of bounding circle/sphere

Reimplemented from util::geometry::GeomObject.

Definition at line 1909 of file geomObjects.cpp.

1909 {
1910
1911 auto box = this->box();
1912 return 0.5 * (box.first - box.second).length();
1913 }
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.

◆ box() [1/2]

std::pair< util::Point, util::Point > util::geometry::ComplexGeomObject::box ( ) const
overridevirtual

Computes the bounding box of object.

Returns
Pair Left-bottom-back and right-top-front corner points of box

Reimplemented from util::geometry::GeomObject.

Definition at line 1875 of file geomObjects.cpp.

1876 {
1877
1878 return box(0.);
1879 }

◆ box() [2/2]

std::pair< util::Point, util::Point > util::geometry::ComplexGeomObject::box ( const double tol) const
overridevirtual

Computes the bounding box of object.

Parameters
tolTolerance/padding used in creating bounding box
Returns
Pair Left-bottom-back and right-top-front corner points of box

Reimplemented from util::geometry::GeomObject.

Definition at line 1881 of file geomObjects.cpp.

1882 {
1883
1884 auto p1 = d_obj[0]->box(tol).first;
1885 auto p2 = d_obj[0]->box(tol).second;
1886
1887 for (size_t i = 1; i < d_objFlag.size(); i++) {
1888
1889 auto q1 = d_obj[i]->box(tol).first;
1890 auto q2 = d_obj[i]->box(tol).second;
1891
1892 for (size_t i = 0; i < 3; i++) {
1893 if (q1[i] < p1[i])
1894 p1[i] = q1[i];
1895 if (q2[i] > p2[i])
1896 p2[i] = q2[i];
1897 }
1898 }
1899
1900 return std::make_pair(p1, p2);
1901 }

◆ center()

util::Point util::geometry::ComplexGeomObject::center ( ) const
overridevirtual

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from util::geometry::GeomObject.

Definition at line 1852 of file geomObjects.cpp.

1852 {
1853
1854 // use formula for centroid of composite objects
1855 auto vol = volume();
1856 if (util::isGreater(vol, 0.)) {
1857 auto center = util::Point();
1858 for (size_t i = 0; i < d_objFlag.size(); i++)
1859 center += d_obj[i]->volume() * d_objFlagInt[i] * d_obj[i]->center();
1860 return (1./vol) * center;
1861 }
1862 else {
1863
1864 // find biggest object that has positive d_objFlagInt
1865 // (that is it is a filling and not void object)
1866 std::vector<double> vol_vec(d_obj.size());
1867 for (size_t i = 0; i < d_obj.size(); i++)
1868 vol_vec[i] = d_obj[i]->volume() * d_objFlagInt[i];
1869
1871 return d_obj[max_vol_obj]->center();
1872 }
1873 }
util::Point center() const override
Computes the center of object.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
size_t maxIndex(const std::vector< T > &data)
Returns the index corresponding to maximum from list of data.
Definition methods.h:38
bool isGreater(const double &a, const double &b)
Returns true if a > b.
Definition function.cpp:15
A structure to represent 3d vectors.
Definition point.h:30

References util::isGreater(), and util::methods::maxIndex().

Here is the call graph for this function:

◆ doesIntersect() [1/2]

bool util::geometry::ComplexGeomObject::doesIntersect ( const std::pair< util::Point, util::Point > &  box) const
overridevirtual

Checks if box intersects this object.

Parameters
boxBox
Returns
True True if intersects

Reimplemented from util::geometry::GeomObject.

Definition at line 2006 of file geomObjects.cpp.

2007 {
2008
2009 // need to check all four corner points
2010 for (auto p: util::getCornerPoints(d_dim, box))
2011 if (this->isInside(p))
2012 return true;
2013
2014 return false;
2015 }
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
Collection of methods useful in simulation.
std::vector< util::Point > getCornerPoints(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns all corner points in the box.
Definition geom.cpp:14

References util::getCornerPoints().

Here is the call graph for this function:

◆ doesIntersect() [2/2]

bool util::geometry::ComplexGeomObject::doesIntersect ( const util::Point x) const
overridevirtual

Checks if point lies exactly on the boundary.

Parameters
xPoint
Returns
True True if it lies on the boundary

Reimplemented from util::geometry::GeomObject.

Definition at line 1966 of file geomObjects.cpp.

1967 {
1968
1969 return isNearBoundary(x, 1.0E-8, false);
1970 }
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons

◆ inscribedRadius()

double util::geometry::ComplexGeomObject::inscribedRadius ( ) const
overridevirtual

Computes the radius of biggest circle/sphere completely within the object.

Returns
Radius Radius of inscribed circle/sphere

Reimplemented from util::geometry::GeomObject.

Definition at line 1903 of file geomObjects.cpp.

1903 {
1904
1905 auto box = this->box();
1906 return 0.5 * (box.first - box.second).length();
1907 }

◆ isInside() [1/2]

bool util::geometry::ComplexGeomObject::isInside ( const std::pair< util::Point, util::Point > &  box) const
overridevirtual

Checks if box is completely inside.

Parameters
boxBox
Returns
True True if box lies inside

Reimplemented from util::geometry::GeomObject.

Definition at line 1972 of file geomObjects.cpp.

1973 {
1974
1975 for (auto p: util::getCornerPoints(d_dim, box))
1976 if (!this->isInside(p))
1977 return false;
1978
1979 return true;
1980 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isInside() [2/2]

bool util::geometry::ComplexGeomObject::isInside ( const util::Point x) const
overridevirtual

Checks if point is inside this object.

Parameters
xPoint
Returns
True If point lies inside

Reimplemented from util::geometry::GeomObject.

Definition at line 1916 of file geomObjects.cpp.

1916 {
1917
1918 // point inside means x should be inside in the object with plus flag and
1919 // outside in the object with minus flag
1920 bool point_inside = d_obj[0]->isInside(x);
1921 for (size_t i = 1; i < d_objFlag.size(); i++) {
1922
1923 const auto &obj_i = d_obj[i];
1924 if (d_objFlagInt[i] < 0)
1925 point_inside = point_inside and !obj_i->isInside(x);
1926 else
1927 point_inside = point_inside or obj_i->isInside(x);
1928 }
1929
1930 return point_inside;
1931 }

◆ isNear() [1/2]

bool util::geometry::ComplexGeomObject::isNear ( const std::pair< util::Point, util::Point > &  box,
const double tol 
) const
overridevirtual

Checks if box is within given distance of this object.

Parameters
boxBox
tolTolerance used in checking the nearness
Returns
True True if box is inside within the tol distance

Reimplemented from util::geometry::GeomObject.

Definition at line 1992 of file geomObjects.cpp.

1994 {
1995
1996 bool is_near = d_obj[0]->isNear(box, tol);
1997 for (size_t i = 1; i < d_objFlag.size(); i++) {
1998
1999 const auto &obj_i = d_obj[i];
2000 is_near = is_near or obj_i->isNear(box, tol);
2001 }
2002
2003 return is_near;
2004 }

◆ isNear() [2/2]

bool util::geometry::ComplexGeomObject::isNear ( const util::Point x,
const double tol 
) const
overridevirtual

Checks if point is within given distance of this object.

Parameters
xPoint
tolTolerance used in checking the nearness
Returns
True True if within the tol distance

Reimplemented from util::geometry::GeomObject.

Definition at line 1938 of file geomObjects.cpp.

1939 {
1940
1941 bool is_near = d_obj[0]->isNear(x, tol);
1942 for (size_t i = 1; i < d_objFlag.size(); i++) {
1943
1944 const auto &obj_i = d_obj[i];
1945 is_near = is_near or obj_i->isNear(x, tol);
1946 }
1947
1948 return is_near;
1949 }

◆ isNearBoundary()

bool util::geometry::ComplexGeomObject::isNearBoundary ( const util::Point x,
const double tol,
const bool within 
) const
overridevirtual

cons

cons

Reimplemented from util::geometry::GeomObject.

Definition at line 1951 of file geomObjects.cpp.

1954 {
1955
1956 bool is_near = d_obj[0]->isNearBoundary(x, tol, within);
1957 for (size_t i = 1; i < d_objFlag.size(); i++) {
1958
1959 const auto &obj_i = d_obj[i];
1960 is_near = is_near or obj_i->isNearBoundary(x, tol, within);
1961 }
1962
1963 return is_near;
1964 }

◆ isOutside() [1/2]

bool util::geometry::ComplexGeomObject::isOutside ( const std::pair< util::Point, util::Point > &  box) const
overridevirtual

Checks if box is outside of the object.

Parameters
boxBox
Returns
True True if box lies outside

Reimplemented from util::geometry::GeomObject.

Definition at line 1982 of file geomObjects.cpp.

1983 {
1984
1985 bool intersect = false;
1986 for (auto p: util::getCornerPoints(d_dim, box))
1988
1989 return !intersect;
1990 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isOutside() [2/2]

bool util::geometry::ComplexGeomObject::isOutside ( const util::Point x) const
overridevirtual

Checks if point is outside of this object.

Parameters
xPoint
Returns
True If point lies outside

Reimplemented from util::geometry::GeomObject.

Definition at line 1934 of file geomObjects.cpp.

1934 {
1935 return !isInside(x);
1936 }

◆ print() [1/2]

void util::geometry::ComplexGeomObject::print ( ) const
inlineoverridevirtual

Prints the information about the object.

Reimplemented from util::geometry::GeomObject.

Definition at line 2714 of file geomObjects.h.

2714{ print(0, 0); };
void print() const override
Prints the information about the object.

References print().

Referenced by print().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print() [2/2]

void util::geometry::ComplexGeomObject::print ( int  nt,
int  lvl 
) const
inlineoverridevirtual

Prints the information about the object.

Parameters
ntNumber of tabs to append before printing
lvlInformation level (higher means more information)

Reimplemented from util::geometry::GeomObject.

Definition at line 2707 of file geomObjects.h.

2707 {
2708 std::cout << printStr(nt, lvl);
2709 };
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.

References d_dim, and printStr().

Here is the call graph for this function:

◆ printStr()

std::string util::geometry::ComplexGeomObject::printStr ( int  nt,
int  lvl 
) const
overridevirtual

Returns the string containing printable information about the object.

Parameters
ntNumber of tabs to append before printing
lvlInformation level (higher means more information)
Returns
string String containing printable information about the object

Reimplemented from util::geometry::GeomObject.

Definition at line 2018 of file geomObjects.cpp.

2018 {
2019
2020 auto tabS = util::io::getTabS(nt);
2021
2022 std::ostringstream oss;
2023
2024 oss << tabS << "------- ComplexGeomObject --------" << std::endl
2025 << std::endl;
2026 oss << tabS << "Name = " << d_name << std::endl;
2027 oss << tabS << "Center = " << center().printStr() << std::endl;
2028 oss << tabS << "Object info:" << std::endl;
2029 auto ocount = 0;
2030 for (const auto &p: d_obj) {
2031 oss << tabS << "Object id: " << ocount << std::endl;
2032 oss << tabS << "Object flag: " << d_objFlag[ocount] << std::endl;
2033 oss << tabS << "Object int flag: " << d_objFlagInt[ocount] << std::endl;
2034 oss << p->printStr(nt + 1, lvl);
2035 ocount++;
2036 }
2037
2038 if (lvl > 0)
2039 oss << tabS << "Bounding box: "
2040 << util::io::printBoxStr(box(0.), nt + 1);
2041
2042 if (lvl == 0)
2043 oss << std::endl;
2044
2045 return oss.str();
2046 }
const std::string d_name
name of object
std::string printBoxStr(const std::pair< util::Point, util::Point > &box, int nt=print_default_tab)
Returns formatted string for output.
Definition io.h:168
std::string getTabS(int nt)
Returns tab spaces of given size.
Definition io.h:40
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition point.h:94

References util::io::getTabS(), and util::io::printBoxStr().

Referenced by print().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ volume()

double util::geometry::ComplexGeomObject::volume ( ) const
overridevirtual

Computes the volume (area in 2d, length in 1d) of object.

Returns
Volume Volume of object

Reimplemented from util::geometry::GeomObject.

Definition at line 1843 of file geomObjects.cpp.

1843 {
1844
1845 double volume = 0.;
1846 for (size_t i = 0; i < d_objFlag.size(); i++)
1847 volume += d_obj[i]->volume() * d_objFlagInt[i];
1848
1849 return volume;
1850 }

Field Documentation

◆ d_dim

size_t util::geometry::ComplexGeomObject::d_dim

Dimension objects live in.

Definition at line 2735 of file geomObjects.h.

Referenced by ComplexGeomObject(), and print().

◆ d_obj

std::vector<std::shared_ptr<util::geometry::GeomObject> > util::geometry::ComplexGeomObject::d_obj

Object.

Definition at line 2717 of file geomObjects.h.

◆ d_objFlag

std::vector<std::string> util::geometry::ComplexGeomObject::d_objFlag

Object flag.

Ordering of objects is important. To describe a rectangle with circular hole, we will have d_obj = {rectangle, circle} and have flag = {plus, minus}. This means final object is rectangle - circle

Definition at line 2727 of file geomObjects.h.

Referenced by ComplexGeomObject().

◆ d_objFlagInt

std::vector<int> util::geometry::ComplexGeomObject::d_objFlagInt

Object integer flags. Here, +1 means object is filling and -1 means object is void.

Definition at line 2732 of file geomObjects.h.

Referenced by ComplexGeomObject().


The documentation for this class was generated from the following files: