2014-05-06 21:20:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011-2014 hasufell
|
|
|
|
*
|
|
|
|
* This file is part of a hasufell project.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation version 2 of the License only.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-05-10 17:33:54 +00:00
|
|
|
/**
|
|
|
|
* @file half_edge.h
|
|
|
|
* Header for the external API of half_edge.c,
|
|
|
|
* primarily holding the common half-edge data
|
|
|
|
* structures.
|
|
|
|
* @brief header of half_edge.c
|
|
|
|
*/
|
|
|
|
|
2014-05-10 17:16:13 +00:00
|
|
|
#ifndef _DROW_ENGINE_HE_OPERATIONS_H
|
|
|
|
#define _DROW_ENGINE_HE_OPERATIONS_H
|
2014-05-06 21:11:42 +00:00
|
|
|
|
|
|
|
|
2014-05-11 12:02:34 +00:00
|
|
|
#include "vector.h"
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
2014-05-07 19:52:36 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
2014-05-13 11:47:13 +00:00
|
|
|
/**
|
|
|
|
* Fault intolerant macro. Will abort the program if the called
|
|
|
|
* function failed.
|
|
|
|
*/
|
|
|
|
#define FACE_NORMAL(...) \
|
|
|
|
{ \
|
|
|
|
if (!face_normal(__VA_ARGS__)) { \
|
|
|
|
fprintf(stderr, "Failure in face_normal()!\n"); \
|
|
|
|
abort(); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fault intolerant macro. Will abort the program if the called
|
|
|
|
* function failed.
|
|
|
|
*/
|
|
|
|
#define VEC_NORMAL(...) \
|
|
|
|
{ \
|
|
|
|
if (!vec_normal(__VA_ARGS__)) { \
|
|
|
|
fprintf(stderr, "Failure in vec_normal()!\n"); \
|
|
|
|
abort(); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fault intolerant macro. Will abort the program if the called
|
|
|
|
* function failed.
|
|
|
|
*/
|
|
|
|
#define FIND_CENTER(...) \
|
|
|
|
{ \
|
|
|
|
if (!find_center(__VA_ARGS__)) { \
|
|
|
|
fprintf(stderr, "Failure in find_center()!\n"); \
|
|
|
|
abort(); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2014-05-13 12:05:02 +00:00
|
|
|
/**
|
|
|
|
* Fault intolerant macro. Will abort the program if the called
|
|
|
|
* function failed.
|
|
|
|
*/
|
|
|
|
#define NORMALIZE_OBJECT(...) \
|
|
|
|
{ \
|
|
|
|
if (!normalize_object(__VA_ARGS__)) { \
|
|
|
|
fprintf(stderr, "Failure in normalize_object()!\n"); \
|
|
|
|
abort(); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2014-05-13 11:47:13 +00:00
|
|
|
|
2014-05-10 17:33:54 +00:00
|
|
|
/**
|
|
|
|
* Typedef for the plain faces
|
|
|
|
* that are not yet converted to real HE_face.
|
|
|
|
*/
|
|
|
|
typedef uint32_t** FACE;
|
|
|
|
|
2014-05-06 21:11:42 +00:00
|
|
|
typedef struct HE_edge HE_edge;
|
|
|
|
typedef struct HE_vert HE_vert;
|
|
|
|
typedef struct HE_face HE_face;
|
2014-05-07 19:52:36 +00:00
|
|
|
typedef struct HE_obj HE_obj;
|
2014-05-15 16:33:43 +00:00
|
|
|
typedef struct color color;
|
2014-05-06 21:11:42 +00:00
|
|
|
|
2014-05-10 15:34:25 +00:00
|
|
|
|
2014-05-06 21:11:42 +00:00
|
|
|
/**
|
|
|
|
* Represents a half-edge.
|
|
|
|
*/
|
|
|
|
struct HE_edge {
|
|
|
|
/**
|
|
|
|
* Start-vertex of the halfe-edge.
|
|
|
|
*/
|
|
|
|
HE_vert *vert;
|
|
|
|
/**
|
|
|
|
* Oppositely oriented adjacent half-edge.
|
2014-05-15 16:52:28 +00:00
|
|
|
* Border edges have a dummy pair which have "face"
|
|
|
|
* and "next" set to NULL.
|
2014-05-06 21:11:42 +00:00
|
|
|
*/
|
|
|
|
HE_edge *pair;
|
|
|
|
/**
|
|
|
|
* Face the half-edge borders.
|
|
|
|
*/
|
|
|
|
HE_face *face;
|
|
|
|
/**
|
|
|
|
* Next half-edge around the face.
|
|
|
|
*/
|
|
|
|
HE_edge *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a vertex with a random attached
|
2014-05-15 16:34:07 +00:00
|
|
|
* half-edge.
|
2014-05-06 21:11:42 +00:00
|
|
|
*/
|
|
|
|
struct HE_vert {
|
2014-05-12 17:48:46 +00:00
|
|
|
/**
|
|
|
|
* A vector pointing
|
|
|
|
* to the coordinates of the vertex.
|
|
|
|
*/
|
|
|
|
vector *vec;
|
2014-05-06 21:11:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* One of the half-edges emanating from the vertex.
|
2014-05-15 16:52:28 +00:00
|
|
|
* It is made sure that this is never a border edge,
|
|
|
|
* unless there are only border edges.
|
2014-05-06 21:11:42 +00:00
|
|
|
*/
|
|
|
|
HE_edge *edge;
|
2014-05-13 18:09:16 +00:00
|
|
|
|
|
|
|
/**
|
2014-05-15 16:52:28 +00:00
|
|
|
* Acceleration structure which saves all potential
|
|
|
|
* pair edges that point TO this vertex. It is used
|
2014-05-13 18:09:16 +00:00
|
|
|
* for finding the pairs when assembling
|
2014-05-15 16:52:28 +00:00
|
|
|
* the HE_edge struct. Note that this does not reliably
|
|
|
|
* save all border edges (which is a non-issue for the
|
|
|
|
* specific purpose of this struct since border-edges
|
|
|
|
* don't qualify for pairs anyway).
|
2014-05-13 18:09:16 +00:00
|
|
|
*/
|
|
|
|
HE_edge **edge_array;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Element count of the edge_array.
|
|
|
|
*/
|
|
|
|
uint32_t eac;
|
2014-05-15 16:33:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Color of the vertex.
|
|
|
|
*/
|
|
|
|
color *col;
|
2014-05-06 21:11:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a face
|
|
|
|
*/
|
|
|
|
struct HE_face {
|
|
|
|
/**
|
|
|
|
* One of the half-edges bordering the face.
|
|
|
|
*/
|
|
|
|
HE_edge *edge;
|
|
|
|
};
|
|
|
|
|
2014-05-07 19:52:36 +00:00
|
|
|
/**
|
|
|
|
* Represents a collection of HE_edge, HE_vert and HE_face
|
|
|
|
* which are all attached to one object. This is useful
|
|
|
|
* for algorithms that need to iterate over one or another.
|
|
|
|
*/
|
|
|
|
struct HE_obj {
|
|
|
|
/**
|
|
|
|
* Array of edges.
|
|
|
|
*/
|
|
|
|
HE_edge *edges;
|
|
|
|
/**
|
|
|
|
* Array of vertices.
|
|
|
|
*/
|
|
|
|
HE_vert *vertices;
|
|
|
|
/**
|
|
|
|
* Array of faces.
|
|
|
|
*/
|
|
|
|
HE_face *faces;
|
|
|
|
/**
|
|
|
|
* Count of edges.
|
|
|
|
*/
|
2014-05-08 15:38:22 +00:00
|
|
|
uint32_t ec;
|
2014-05-07 19:52:36 +00:00
|
|
|
/**
|
|
|
|
* Count of vertices.
|
|
|
|
*/
|
2014-05-08 15:38:22 +00:00
|
|
|
uint32_t vc;
|
2014-05-07 19:52:36 +00:00
|
|
|
/**
|
|
|
|
* Count of faces.
|
|
|
|
*/
|
2014-05-08 15:38:22 +00:00
|
|
|
uint32_t fc;
|
2014-05-07 19:52:36 +00:00
|
|
|
};
|
|
|
|
|
2014-05-15 16:33:43 +00:00
|
|
|
/**
|
|
|
|
* Color.
|
|
|
|
*/
|
|
|
|
struct color {
|
|
|
|
float red;
|
|
|
|
float green;
|
|
|
|
float blue;
|
|
|
|
};
|
|
|
|
|
2014-05-06 21:11:42 +00:00
|
|
|
|
2014-05-12 21:02:10 +00:00
|
|
|
bool face_normal(HE_edge const * const edge,
|
|
|
|
vector *vec);
|
2014-05-12 18:20:03 +00:00
|
|
|
bool vec_normal(HE_vert const * const vert, vector *vec);
|
2014-05-11 12:02:34 +00:00
|
|
|
bool find_center(HE_obj const * const obj, vector *vec);
|
2014-05-10 19:05:08 +00:00
|
|
|
float get_normalized_scale_factor(HE_obj const * const obj);
|
2014-05-13 12:05:02 +00:00
|
|
|
bool normalize_object(HE_obj *obj);
|
2014-05-10 17:33:54 +00:00
|
|
|
HE_obj *parse_obj(char const * const filename);
|
2014-05-12 21:02:10 +00:00
|
|
|
void delete_object(HE_obj *obj);
|
2014-05-10 17:16:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
#endif /* _DROW_ENGINE_HE_OPERATIONS_H */
|