gctl/lib/geometry/node.h
2024-09-10 15:45:07 +08:00

152 lines
4.7 KiB
C++

/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
* ██║ ██║██║ ██║ ██║
* ╚██████╔╝╚██████╗ ██║ ███████╗
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
*
* GCTL is distributed under a dual licensing scheme. You can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 2
* of the License, or (at your option) any later version. You should have
* received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* If the terms and conditions of the LGPL v.2. would prevent you from using
* the GCTL, please consider the option to obtain a commercial license for a
* fee. These licenses are offered by the GCTL's original author. As a rule,
* licenses are provided "as-is", unlimited in time for a one time fee. Please
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
* to include some description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#ifndef _GCTL_NODE_H
#define _GCTL_NODE_H
#include "vertex.h"
#include "entity.h"
namespace gctl
{
// Declaration of the basic node type
template <typename A> struct type_node;
// node type of attribute type of void
typedef type_node<void> enode;
/**
* @brief 点结构体
*/
template <typename A>
struct type_node : public entity<vertex3dc, 1, A>
{
/**
* Constructor
*/
type_node();
/**
* @brief Set object from parameters
*
* @warning This function will locate memories to store vertice
*
* @param[in] p0 The location point
* @param[in] index The element index
*/
type_node(const point3dc &p0, int index = 0);
/**
* @brief Set object's parameters
*
* @param vert0 The location vertex
* @param[in] index The index
*/
type_node(vertex3dc &vert0, int index = 0);
/**
* @brief De-constructor
*/
virtual ~type_node(){}
/**
* @brief Set object from parameters
*
* @warning This function will locate memories to store vertice
*
* @param[in] p0 The location point
* @param[in] index The element index
*/
void set(const point3dc &p0, int index = 0);
/**
* @brief Set object's parameters
*
* @param vert0 The location vertex
* @param[in] index The index
*/
void set(vertex3dc &vert0, int index = 0);
/**
* @brief Reset the structure to initial state
*/
void reset();
};
template <typename A>
type_node<A>::type_node() : entity<vertex3dc, 1, A>::entity(){}
template <typename A>
type_node<A>::type_node(const point3dc &p0, int index) : type_node()
{
set(p0, index);
}
template <typename A>
type_node<A>::type_node(vertex3dc &vert0, int index) : type_node()
{
set(vert0, index);
}
template <typename A>
void type_node<A>::set(const point3dc &p0, int index)
{
if (index < 0)
{
throw out_of_range("Invalid index number, From type_node::set(...)");
}
this->vert[0] = new vertex3dc;
this->self_host = true;
this->id = index;
this->vert[0]->set(p0, index);
return;
}
template <typename A>
void type_node<A>::set(vertex3dc &vert0, int index)
{
if (index < 0)
{
throw out_of_range("Invalid index number, From type_node::set(...)");
}
this->id = index;
this->vert[0] = &vert0;
return;
}
template <typename A>
void type_node<A>::reset()
{
entity<vertex3dc, 1, A>::reset();
return;
}
template <typename A, typename B>
void copy_type_node(type_node<A> *tar, const type_node<B> *src)
{
copy_entity(tar, src);
return;
}
}
#endif // _GCTL_NODE_H