Skip to content
Snippets Groups Projects
Commit bd1ba828 authored by Karsten Rink's avatar Karsten Rink
Browse files

added functionality to find all nodes that are connected via edges and via...

added functionality to find all nodes that are connected via edges and via element to other nodes; replaces all cout's with appropriate logog messages
parent 756919d5
No related branches found
No related tags found
No related merge requests found
Showing
with 138 additions and 13 deletions
...@@ -37,7 +37,7 @@ double RunTime::elapsed() ...@@ -37,7 +37,7 @@ double RunTime::elapsed()
#ifndef _WIN32 #ifndef _WIN32
return (_stop.tv_sec + _stop.tv_usec/1000000.0 - (_start.tv_sec + _start.tv_usec/1000000.0)); return (_stop.tv_sec + _stop.tv_usec/1000000.0 - (_start.tv_sec + _start.tv_usec/1000000.0));
#else #else
return (_stop - _start) / 1000; return (_stop - _start) / 1000.0;
#endif #endif
} }
......
...@@ -14,13 +14,15 @@ ...@@ -14,13 +14,15 @@
#define UNIQUELISTINSERT_H_ #define UNIQUELISTINSERT_H_
#include <list> #include <list>
#include <vector>
namespace BaseLib { namespace BaseLib {
void uniqueListInsert (std::list<size_t>& list, size_t element) template<class T>
void uniqueListInsert (std::list<T>& list, T element)
{ {
// search element // search element
std::list<size_t>::const_iterator it; std::list<T>::const_iterator it;
for (it = list.begin (); it != list.end(); it++) { for (it = list.begin (); it != list.end(); it++) {
if (*it == element) return; if (*it == element) return;
} }
...@@ -28,6 +30,18 @@ void uniqueListInsert (std::list<size_t>& list, size_t element) ...@@ -28,6 +30,18 @@ void uniqueListInsert (std::list<size_t>& list, size_t element)
list.push_back (element); list.push_back (element);
} }
template<class T>
void uniqueVectorInsert (std::vector<T>& vec, T element)
{
// search element
std::vector<T>::const_iterator it;
for (it = vec.begin (); it != vec.end(); ++it)
if (*it == element) return;
// element not found -> insert
vec.push_back (element);
}
} // end namespace BaseLib } // end namespace BaseLib
#endif /* UNIQUELISTINSERT_H_ */ #endif /* UNIQUELISTINSERT_H_ */
...@@ -110,6 +110,7 @@ ADD_DEPENDENCIES ( ogs-gui VtkVis OGSProject ) ...@@ -110,6 +110,7 @@ ADD_DEPENDENCIES ( ogs-gui VtkVis OGSProject )
IF(MSVC) IF(MSVC)
# Set linker flags # Set linker flags
SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:MSVCRT") SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:MSVCRT")
TARGET_LINK_LIBRARIES( ogs-gui winmm)
ENDIF(MSVC) ENDIF(MSVC)
IF(OGS_BUILD_INFO) IF(OGS_BUILD_INFO)
......
...@@ -4,13 +4,15 @@ ...@@ -4,13 +4,15 @@
#ifdef OGS_USE_OPENSG #ifdef OGS_USE_OPENSG
#include <OpenSG/OSGBaseFunctions.h> #include <OpenSG/OSGBaseFunctions.h>
#endif #endif
#include "logog.hpp"
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
#ifdef OGS_USE_OPENSG #ifdef OGS_USE_OPENSG
OSG::osgInit(argc, argv); OSG::osgInit(argc, argv);
#endif #endif
LOGOG_INITIALIZE();
logog::Cout* logogCout = new logog::Cout;
QApplication a(argc, argv); QApplication a(argc, argv);
setlocale(LC_NUMERIC,"C"); setlocale(LC_NUMERIC,"C");
MainWindow* w = new MainWindow(); MainWindow* w = new MainWindow();
...@@ -19,6 +21,8 @@ int main(int argc, char* argv[]) ...@@ -19,6 +21,8 @@ int main(int argc, char* argv[])
int returncode = a.exec(); int returncode = a.exec();
delete w; delete w;
delete logogCout;
LOGOG_SHUTDOWN();
#ifdef OGS_USE_OPENSG #ifdef OGS_USE_OPENSG
OSG::osgExit(); OSG::osgExit();
#endif // OGS_USE_OPENSG #endif // OGS_USE_OPENSG
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
// BaseLib // BaseLib
#include "swap.h" #include "swap.h"
#include "printList.h" #include "printList.h"
#include "uniqueListInsert.h" #include "uniqueInsert.h"
// MathLib // MathLib
#include "EarClippingTriangulation.h" #include "EarClippingTriangulation.h"
......
...@@ -52,6 +52,13 @@ double Edge::computeVolume() ...@@ -52,6 +52,13 @@ double Edge::computeVolume()
return sqrt(MathLib::sqrDist(_nodes[0]->getCoords(), _nodes[1]->getCoords())); return sqrt(MathLib::sqrDist(_nodes[0]->getCoords(), _nodes[1]->getCoords()));
} }
bool Edge::isEdge(unsigned idx1, unsigned idx2) const
{
if (0==idx1 && 1==idx2) return true;
if (1==idx1 && 0==idx2) return true;
return false;
}
Element* Edge::clone() const Element* Edge::clone() const
{ {
return new Edge(*this); return new Edge(*this);
......
...@@ -75,8 +75,15 @@ public: ...@@ -75,8 +75,15 @@ public:
/// Get the number of nodes for this element. /// Get the number of nodes for this element.
virtual unsigned getNNodes() const { return 2; }; virtual unsigned getNNodes() const { return 2; };
/**
* Method returns the type of the element. In this case EDGE will be returned.
* @return MshElemType::EDGE
*/
virtual MshElemType::type getType() const { return MshElemType::EDGE; } virtual MshElemType::type getType() const { return MshElemType::EDGE; }
/// Returns true if these two indeces form an edge and false otherwise
bool isEdge(unsigned i, unsigned j) const;
virtual Element* clone() const; virtual Element* clone() const;
/** /**
...@@ -88,7 +95,7 @@ public: ...@@ -88,7 +95,7 @@ public:
protected: protected:
double computeVolume(); double computeVolume();
/// 1D elements have no edges. /// 1D elements have no edges.
Node const* getEdgeNode(unsigned edge_id, unsigned node_id) const { (void)edge_id; (void)node_id; return NULL; }; Node* getEdgeNode(unsigned edge_id, unsigned node_id) const { (void)edge_id; (void)node_id; return NULL; };
/// 1D elements have no faces. /// 1D elements have no faces.
Node* getFaceNode(unsigned face_id, unsigned node_id) const { (void)face_id; (void)node_id; return NULL; }; Node* getFaceNode(unsigned face_id, unsigned node_id) const { (void)face_id; (void)node_id; return NULL; };
......
...@@ -59,7 +59,6 @@ bool Element::addNeighbor(Element* e) ...@@ -59,7 +59,6 @@ bool Element::addNeighbor(Element* e)
if (_nodes[i] == e_nodes[j]) if (_nodes[i] == e_nodes[j])
{ {
face_nodes[count] = _nodes[i]; face_nodes[count] = _nodes[i];
//std::cout << _nodes[i]->getID() << " == " << e_nodes[j]->getID() << std::endl;
// increment shared nodes counter and check if enough nodes are similar to be sure e is a neighbour of this // increment shared nodes counter and check if enough nodes are similar to be sure e is a neighbour of this
if ((++count)>=dim) if ((++count)>=dim)
{ {
...@@ -105,6 +104,15 @@ const Element* Element::getNeighbor(unsigned i) const ...@@ -105,6 +104,15 @@ const Element* Element::getNeighbor(unsigned i) const
return NULL; return NULL;
} }
unsigned Element::getNodeIDinElement(const MeshLib::Node* node) const
{
const unsigned nNodes (this->getNNodes());
for (unsigned i(0); i<nNodes; i++)
if (node == _nodes[i])
return i;
return std::numeric_limits<unsigned>::max();
}
const Node* Element::getNode(unsigned i) const const Node* Element::getNode(unsigned i) const
{ {
if (i < getNNodes()) if (i < getNNodes())
...@@ -136,5 +144,6 @@ bool Element::hasNeighbor(Element* elem) const ...@@ -136,5 +144,6 @@ bool Element::hasNeighbor(Element* elem) const
return false; return false;
} }
} }
...@@ -93,6 +93,9 @@ public: ...@@ -93,6 +93,9 @@ public:
/// Get the number of nodes for this element. /// Get the number of nodes for this element.
virtual unsigned getNNodes() const = 0; virtual unsigned getNNodes() const = 0;
/// Returns the position of the given node in the node array of this element.
virtual unsigned getNodeIDinElement(const MeshLib::Node* node) const;
/** /**
* Get the global index for the Node with local index i. * Get the global index for the Node with local index i.
* The index i should be at most the number of nodes of the element. * The index i should be at most the number of nodes of the element.
...@@ -109,11 +112,15 @@ public: ...@@ -109,11 +112,15 @@ public:
/// Get the value for this element. /// Get the value for this element.
unsigned getValue() const { return _value; }; unsigned getValue() const { return _value; };
/// Returns true if elem is a neighbour of this element and false otherwise.
bool hasNeighbor(Element* elem) const; bool hasNeighbor(Element* elem) const;
/// Destructor /// Destructor
virtual ~Element(); virtual ~Element();
/// Returns true if these two indeces form an edge and false otherwise
virtual bool isEdge(unsigned i, unsigned j) const = 0;
/** /**
* Method clone is a pure virtual method in the abstract base class Element. * Method clone is a pure virtual method in the abstract base class Element.
* It has to be implemented in the derived classes (for instance in class Hex). * It has to be implemented in the derived classes (for instance in class Hex).
...@@ -143,11 +150,12 @@ protected: ...@@ -143,11 +150,12 @@ protected:
Element(unsigned value = 0); Element(unsigned value = 0);
/// Return a specific edge node. /// Return a specific edge node.
virtual Node const* getEdgeNode(unsigned edge_id, unsigned node_id) const = 0; virtual Node* getEdgeNode(unsigned edge_id, unsigned node_id) const = 0;
/// Returns the ID of a face given an array of nodes. /// Returns the ID of a face given an array of nodes.
virtual unsigned identifyFace(Node* nodes[3]) const = 0; virtual unsigned identifyFace(Node* nodes[3]) const = 0;
Node** _nodes; Node** _nodes;
unsigned _value; unsigned _value;
Element** _neighbors; Element** _neighbors;
......
...@@ -115,6 +115,16 @@ const Element* Hex::getFace(unsigned i) const ...@@ -115,6 +115,16 @@ const Element* Hex::getFace(unsigned i) const
return NULL; return NULL;
} }
bool Hex::isEdge(unsigned idx1, unsigned idx2) const
{
for (unsigned i(0); i<12; i++)
{
if (_edge_nodes[i][0]==idx1 && _edge_nodes[i][1]==idx2) return true;
if (_edge_nodes[i][1]==idx1 && _edge_nodes[i][0]==idx2) return true;
}
return false;
}
Element* Hex::clone() const Element* Hex::clone() const
{ {
return new Hex(*this); return new Hex(*this);
......
...@@ -81,6 +81,9 @@ public: ...@@ -81,6 +81,9 @@ public:
*/ */
virtual MshElemType::type getType() const { return MshElemType::HEXAHEDRON; } virtual MshElemType::type getType() const { return MshElemType::HEXAHEDRON; }
/// Returns true if these two indeces form an edge and false otherwise
bool isEdge(unsigned i, unsigned j) const;
/** /**
* Method clone is inherited from class Element. It makes a deep copy of the Hex instance. * Method clone is inherited from class Element. It makes a deep copy of the Hex instance.
* @return an exact copy of the object * @return an exact copy of the object
...@@ -98,7 +101,7 @@ protected: ...@@ -98,7 +101,7 @@ protected:
double computeVolume(); double computeVolume();
/// Return a specific edge node. /// Return a specific edge node.
inline Node const* getEdgeNode(unsigned edge_id, unsigned node_id) const { return _nodes[_edge_nodes[edge_id][node_id]]; }; inline Node* getEdgeNode(unsigned edge_id, unsigned node_id) const { return _nodes[_edge_nodes[edge_id][node_id]]; };
/// Returns the ID of a face given an array of nodes. /// Returns the ID of a face given an array of nodes.
unsigned identifyFace(Node* nodes[3]) const; unsigned identifyFace(Node* nodes[3]) const;
......
...@@ -120,6 +120,16 @@ unsigned Prism::getNFaceNodes(unsigned i) const ...@@ -120,6 +120,16 @@ unsigned Prism::getNFaceNodes(unsigned i) const
return 0; return 0;
} }
bool Prism::isEdge(unsigned idx1, unsigned idx2) const
{
for (unsigned i(0); i<9; i++)
{
if (_edge_nodes[i][0]==idx1 && _edge_nodes[i][1]==idx2) return true;
if (_edge_nodes[i][1]==idx1 && _edge_nodes[i][0]==idx2) return true;
}
return false;
}
Element* Prism::clone() const Element* Prism::clone() const
{ {
return new Prism(*this); return new Prism(*this);
......
...@@ -79,6 +79,9 @@ public: ...@@ -79,6 +79,9 @@ public:
*/ */
virtual MshElemType::type getType() const { return MshElemType::PRISM; } virtual MshElemType::type getType() const { return MshElemType::PRISM; }
/// Returns true if these two indeces form an edge and false otherwise
bool isEdge(unsigned i, unsigned j) const;
/** /**
* Method clone is inherited from class Element. It makes a deep copy of the * Method clone is inherited from class Element. It makes a deep copy of the
* Hex instance employing the copy constructor of class Prism. * Hex instance employing the copy constructor of class Prism.
...@@ -102,7 +105,7 @@ protected: ...@@ -102,7 +105,7 @@ protected:
double computeVolume(); double computeVolume();
/// Return a specific edge node. /// Return a specific edge node.
inline Node const* getEdgeNode(unsigned edge_id, unsigned node_id) const { return _nodes[_edge_nodes[edge_id][node_id]]; }; inline Node* getEdgeNode(unsigned edge_id, unsigned node_id) const { return _nodes[_edge_nodes[edge_id][node_id]]; };
/// Returns the ID of a face given an array of nodes. /// Returns the ID of a face given an array of nodes.
unsigned identifyFace(Node* nodes[3]) const; unsigned identifyFace(Node* nodes[3]) const;
......
...@@ -119,6 +119,16 @@ unsigned Pyramid::getNFaceNodes(unsigned i) const ...@@ -119,6 +119,16 @@ unsigned Pyramid::getNFaceNodes(unsigned i) const
return 0; return 0;
} }
bool Pyramid::isEdge(unsigned idx1, unsigned idx2) const
{
for (unsigned i(0); i<8; i++)
{
if (_edge_nodes[i][0]==idx1 && _edge_nodes[i][1]==idx2) return true;
if (_edge_nodes[i][1]==idx1 && _edge_nodes[i][0]==idx2) return true;
}
return false;
}
Element* Pyramid::clone() const Element* Pyramid::clone() const
{ {
return new Pyramid(*this); return new Pyramid(*this);
......
...@@ -77,6 +77,9 @@ public: ...@@ -77,6 +77,9 @@ public:
*/ */
virtual MshElemType::type getType() const { return MshElemType::PYRAMID; } virtual MshElemType::type getType() const { return MshElemType::PYRAMID; }
/// Returns true if these two indeces form an edge and false otherwise
bool isEdge(unsigned i, unsigned j) const;
/** /**
* Method clone is inherited from class Element. It makes a deep copy of the * Method clone is inherited from class Element. It makes a deep copy of the
* Pyramid instance employing the copy constructor of class Pyramid. * Pyramid instance employing the copy constructor of class Pyramid.
...@@ -100,7 +103,7 @@ protected: ...@@ -100,7 +103,7 @@ protected:
double computeVolume(); double computeVolume();
/// Return a specific edge node. /// Return a specific edge node.
inline Node const* getEdgeNode(unsigned edge_id, unsigned node_id) const { return _nodes[_edge_nodes[edge_id][node_id]]; }; inline Node* getEdgeNode(unsigned edge_id, unsigned node_id) const { return _nodes[_edge_nodes[edge_id][node_id]]; };
/// Returns the ID of a face given an array of nodes. /// Returns the ID of a face given an array of nodes.
unsigned identifyFace(Node* nodes[3]) const; unsigned identifyFace(Node* nodes[3]) const;
......
...@@ -75,6 +75,16 @@ double Quad::computeVolume() ...@@ -75,6 +75,16 @@ double Quad::computeVolume()
+ MathLib::calcTriangleArea(_nodes[2]->getCoords(), _nodes[3]->getCoords(), _nodes[0]->getCoords()); + MathLib::calcTriangleArea(_nodes[2]->getCoords(), _nodes[3]->getCoords(), _nodes[0]->getCoords());
} }
bool Quad::isEdge(unsigned idx1, unsigned idx2) const
{
for (unsigned i(0); i<4; i++)
{
if (_edge_nodes[i][0]==idx1 && _edge_nodes[i][1]==idx2) return true;
if (_edge_nodes[i][1]==idx1 && _edge_nodes[i][0]==idx2) return true;
}
return false;
}
Element* Quad::clone() const Element* Quad::clone() const
{ {
return new Quad(*this); return new Quad(*this);
......
...@@ -62,6 +62,9 @@ public: ...@@ -62,6 +62,9 @@ public:
*/ */
virtual MshElemType::type getType() const { return MshElemType::QUAD; } virtual MshElemType::type getType() const { return MshElemType::QUAD; }
/// Returns true if these two indeces form an edge and false otherwise
bool isEdge(unsigned i, unsigned j) const;
/** /**
* Method clone is inherited from class Element. It makes a deep copy of the Quad instance. * Method clone is inherited from class Element. It makes a deep copy of the Quad instance.
* @return an exact copy of the object * @return an exact copy of the object
...@@ -85,7 +88,7 @@ protected: ...@@ -85,7 +88,7 @@ protected:
protected: protected:
/// Return a specific edge node. /// Return a specific edge node.
inline Node const* getEdgeNode(unsigned edge_id, unsigned node_id) const { return _nodes[_edge_nodes[edge_id][node_id]]; }; inline Node* getEdgeNode(unsigned edge_id, unsigned node_id) const { return _nodes[_edge_nodes[edge_id][node_id]]; };
/// Returns the ID of a face given an array of nodes. /// Returns the ID of a face given an array of nodes.
unsigned identifyFace(Node* nodes[3]) const; unsigned identifyFace(Node* nodes[3]) const;
......
...@@ -105,6 +105,16 @@ const Element* Tet::getFace(unsigned i) const ...@@ -105,6 +105,16 @@ const Element* Tet::getFace(unsigned i) const
return NULL; return NULL;
} }
bool Tet::isEdge(unsigned idx1, unsigned idx2) const
{
for (unsigned i(0); i<6; i++)
{
if (_edge_nodes[i][0]==idx1 && _edge_nodes[i][1]==idx2) return true;
if (_edge_nodes[i][1]==idx1 && _edge_nodes[i][0]==idx2) return true;
}
return false;
}
Element* Tet::clone() const Element* Tet::clone() const
{ {
return new Tet(*this); return new Tet(*this);
......
...@@ -76,6 +76,9 @@ public: ...@@ -76,6 +76,9 @@ public:
*/ */
virtual MshElemType::type getType() const { return MshElemType::TETRAHEDRON; } virtual MshElemType::type getType() const { return MshElemType::TETRAHEDRON; }
/// Returns true if these two indeces form an edge and false otherwise
bool isEdge(unsigned i, unsigned j) const;
/** /**
* Method clone is inherited from class Element. It makes a deep copy of the Tet instance. * Method clone is inherited from class Element. It makes a deep copy of the Tet instance.
* @return an exact copy of the object * @return an exact copy of the object
...@@ -104,7 +107,7 @@ protected: ...@@ -104,7 +107,7 @@ protected:
* @param node_id the id of the node within the edge (either 0 or 1) * @param node_id the id of the node within the edge (either 0 or 1)
* @return a pointer to the internal Node * @return a pointer to the internal Node
*/ */
inline Node const* getEdgeNode(unsigned edge_id, unsigned node_id) const { return _nodes[_edge_nodes[edge_id][node_id]]; }; inline Node* getEdgeNode(unsigned edge_id, unsigned node_id) const { return _nodes[_edge_nodes[edge_id][node_id]]; };
/// Returns the ID of a face given an array of nodes. /// Returns the ID of a face given an array of nodes.
unsigned identifyFace(Node* nodes[3]) const; unsigned identifyFace(Node* nodes[3]) const;
......
...@@ -67,6 +67,16 @@ Tri::~Tri() ...@@ -67,6 +67,16 @@ Tri::~Tri()
{ {
} }
bool Tri::isEdge(unsigned idx1, unsigned idx2) const
{
for (unsigned i(0); i<3; i++)
{
if (_edge_nodes[i][0]==idx1 && _edge_nodes[i][1]==idx2) return true;
if (_edge_nodes[i][1]==idx1 && _edge_nodes[i][0]==idx2) return true;
}
return false;
}
Element* Tri::clone() const Element* Tri::clone() const
{ {
return new Tri(*this); return new Tri(*this);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment