cee::ug::DataNodes

class DataNodes : public RefCountedObject

Collection of coordinates (and optionally ids) of the element nodes in a part.

../_images/uml_datapart.png

The DataElements object describes the connectivities for all the elements in a DataPart. The node positions are stored in the DataNodes object. All connectivity indices must refer to a valid index in the node array in the corresponding data nodes. A DataElements object and a DataNodes object together defines a DataPart.

The nodes are stored in double precision, and the ids are stored as integers.

Note! The class is reference counted and can be shared between multiple parts. Remember that since this object is reference counted it should never be created on the stack.

Nodes are inserted using setNode(), setNodes() or setNodesFloat(). If DataNodes are set to use ids, these are set using setNodeId() or setNodeIds(). Call hasNodeIds() on the DataNodes object to check if ids are expected. Whether node ids are used or not is specified upon construction of the DataNodes object. Get the number of nodes in the existing node array with nodeCount() and query individual nodes with node() and nodeId().

Example

Example of a simple part containing two triangles.

Create a DataNodes object which is a collection of nodes used for building the part. In this example you will use 4 nodes to create two triangles. Important! The nodes object must be set to the correct size before setting the actual node coordinates!

cee::PtrRef<cee::ug::DataNodes> nodes = new cee::ug::DataNodes(false);
nodes->resize(5);
nodes->setNode(0, cee::Vec3d(0, 1, 0));
nodes->setNode(1, cee::Vec3d(0, 0, 0));
nodes->setNode(2, cee::Vec3d(1, 0, 0));
nodes->setNode(3, cee::Vec3d(2, 0, 0));
nodes->setNode(4, cee::Vec3d(2, 1, 0));

In addition to the node coordinates, the part need to know about the connectivities. Create a DataElements object describing the connectivities for the two triangle elements.

int c[] = { 0, 1, 2, 2, 3, 4 };
std::vector<unsigned int> eltNodes1(c, c + 3);    // First triangle
std::vector<unsigned int> eltNodes2(c + 3, c + 6);  // Second triangle
cee::PtrRef<cee::ug::DataElements> elements = new cee::ug::DataElements(false, 0);
elements->addElement(cee::ug::Element::TRIANGLES, eltNodes1);
elements->addElement(cee::ug::Element::TRIANGLES, eltNodes2);

Add the nodes and elements to the part object

int partId = 1;
cee::PtrRef<cee::ug::DataPart> part = new cee::ug::DataPart(partId);
part->setNodes(nodes.get());
part->setElements(elements.get());

See the complete source code at: UnstructGrid: Simple Model with Two Triangles

Tutorials

Public Functions

DataNodes(bool hasNodeIds)

Constructs an empty DataNodes object.

Usage of node ids needs to be decided at construction of the object.

size_t nodeCount() const

Returns the number of nodes in the object.

Vec3d node(size_t index) const

Returns the node coordinates at the given index.

The method will assert if the index is out of range.

void resize(size_t nodeCount)

Sets the number of nodes in the object.

The current nodes in the object will be kept up to the given count (if shrinking). It is necessary to use this method to allocate space before calling the single value set function setNode().

void setNode(size_t index, const Vec3d &node)

Sets node coordinate at specified index.

See also

resize()

Warning

The specified index must be a valid index. Either call one of the setNodes() methods or call resize() prior to calling this method.

void setNodes(const std::vector<Vec3d> &nodes)

Sets the node coordinates from a std::vector of Vec3d.

Calling this function will allocate memory for the node coordinates (and node ids if configured) and will completely replace any existing node coordinates.

void setNodes(const double nodes[], size_t nodeCount)

Sets the node coordinates from an array of doubles.

The array must be at least nodeCount*3 items long, as nodeCount is the number of nodes, not the number of doubles in the array.

Calling this function will allocate memory for the node coordinates (and node ids if configured) and will completely replace any existing node coordinates.

void setNodesFloat(const float nodes[], size_t nodeCount)

Sets the node coordinates from an array of floats.

The array must be at least nodeCount*3 items long, as nodeCount is the number of nodes, not the number of floats in the array.

Calling this function will allocate memory for the node coordinates (and node ids if configured) and will completely replace any existing node coordinates.

Note that this is only provided for convenience, and that the nodes will internally be stored as doubles

bool hasNodeIds() const

Returns true if this object has node collection has node ids.

This is the case if the model was read from a file with node ids or if the object was constructed with hasNodeIds=true in the constructor.

int nodeId(size_t index) const

Returns the id for the node at the given index.

The method will assert if the index is out of range.

size_t nodeIndex(int nodeId) const

Returns the index for the node with the given Id.

The method will assert if there are no ids defined. It will return cee::UNDEFINED_SIZE_T if the the given id is not found

void setNodeId(size_t index, int nodeId)

Sets the id of the node at the given index.

Warning

The method will assert if the index is out of range.

void setNodeIds(const std::vector<int> &nodeIds)

Sets the node ids from a std::vector of integers.

Warning

Node coordinates must already be specified or resize() must have been called. The number of elements in the nodeIds array must be equal to the current node count.

void setNodeIds(const int nodeIds[], size_t nodeCount)

Sets the node ids from an array of integers.

The array must be at least nodeCount items long.

Warning

Node coordinates must already be specified or resize() must have been called. The number of elements in the nodeIds array must be equal to the current node count.

const double *rawNodesPointer() const

Returns a raw pointer on the node coordinates array.

const int *rawIdsPointer() const

Returns a raw pointer on the node id’s array.