cbec90699f
- creato il progetto in Visual Studio per compilare come libreria statica - modifiche al codice originale per integrarlo nelle nostre librerie.
322 lines
9.2 KiB
C++
322 lines
9.2 KiB
C++
/*****************************************************************************/
|
|
/* */
|
|
/* F I S T : Fast, Industrial-Strength Triangulation */
|
|
/* */
|
|
/*****************************************************************************/
|
|
/* */
|
|
/* (C) Martin Held */
|
|
/* (C) Universitaet Salzburg, Salzburg, Austria */
|
|
/* */
|
|
/* This code is not in the public domain. All rights reserved! Please make */
|
|
/* sure to read the full copyright statement contained in api_functions.cpp. */
|
|
/* */
|
|
/*****************************************************************************/
|
|
|
|
#ifdef GRAPHICS
|
|
|
|
/* */
|
|
/* get standard libraries */
|
|
/* */
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <assert.h>
|
|
|
|
/* */
|
|
/* get my header files */
|
|
/* */
|
|
#include "fpkernel.h"
|
|
#include "martin.h"
|
|
#include "defs.h"
|
|
#include "list.h"
|
|
#include "header.h"
|
|
#include "graphics.h"
|
|
|
|
|
|
/* */
|
|
/* prototypes of functions provided in this file */
|
|
/* */
|
|
void Redraw(global_struct *all);
|
|
void AddPntToBuffer(redrawdef *redraw, int index, int color);
|
|
void AddEdgeToBuffer(redrawdef *redraw, int index1, int index2, int color);
|
|
void AddTriToBuffer(redrawdef *redraw, int index1, int index2, int index3,
|
|
int color1, int color2);
|
|
void DecrementPntBuffer(redrawdef *redraw);
|
|
void FreeDrawingBuffer(redrawdef *redraw);
|
|
void DecrementEdgeBuffer(redrawdef *redraw);
|
|
void ResetTriBuffer(redrawdef *redraw);
|
|
void UpdatePntEdgeBuffers(global_struct *all);
|
|
void ResetBufferData(redrawdef *redraw);
|
|
|
|
#ifdef PARTITION_FIST
|
|
void UpdateTriBuffer(global_struct *all);
|
|
#endif
|
|
|
|
#define BLOCK_SIZE 1024
|
|
|
|
|
|
void ResetBufferData(redrawdef *redraw)
|
|
{
|
|
redraw->num_pnt_buf = 0;
|
|
redraw->num_edge_buf = 0;
|
|
redraw->num_tri_buf = 0;
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
|
|
void Redraw(global_struct *all)
|
|
{
|
|
redrawdef *redraw = &all->c_redraw;
|
|
datadef *data = &all->c_data;
|
|
|
|
int i;
|
|
char text[10];
|
|
|
|
for (i = 0; i < redraw->num_tri_buf; ++i) {
|
|
assert(InPointsList(data, redraw->tri_buf[i].index1));
|
|
assert(InPointsList(data, redraw->tri_buf[i].index2));
|
|
assert(InPointsList(data, redraw->tri_buf[i].index3));
|
|
DrawTri(data->points[redraw->tri_buf[i].index1],
|
|
data->points[redraw->tri_buf[i].index2],
|
|
data->points[redraw->tri_buf[i].index3],
|
|
redraw->tri_buf[i].color1,
|
|
redraw->tri_buf[i].color2);
|
|
}
|
|
|
|
for (i = 0; i < redraw->num_edge_buf; ++i) {
|
|
assert(InPointsList(data, redraw->edge_buf[i].index1));
|
|
assert(InPointsList(data, redraw->edge_buf[i].index2));
|
|
DrawSeg(data->points[redraw->edge_buf[i].index1],
|
|
data->points[redraw->edge_buf[i].index2],
|
|
redraw->edge_buf[i].color);
|
|
}
|
|
|
|
if (all->draw_pnts) {
|
|
for (i = 0; i < redraw->num_pnt_buf; ++i) {
|
|
assert(InPointsList(data, redraw->pnt_buf[i].index));
|
|
DrawPnt(data->points[redraw->pnt_buf[i].index],
|
|
redraw->pnt_buf[i].color);
|
|
if(all->draw_point_idx) {
|
|
sprintf(text, "%i",redraw->pnt_buf[i].index);
|
|
DrawText(data->points[redraw->pnt_buf[i].index], Orange, text);
|
|
}
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
void AddPntToBuffer(redrawdef *redraw, int index, int color)
|
|
{
|
|
#ifdef PARTITION_FIST
|
|
#pragma omp critical (point)
|
|
{
|
|
#endif
|
|
if (redraw->num_pnt_buf >= redraw->max_num_pnt_buf) {
|
|
redraw->max_num_pnt_buf += BLOCK_SIZE;
|
|
redraw->pnt_buf =
|
|
(pnt_buffer*) ReallocateArray(redraw->memptr,
|
|
redraw->pnt_buf,
|
|
redraw->max_num_pnt_buf,
|
|
sizeof(pnt_buffer),
|
|
"redraw:pnt_buf");
|
|
}
|
|
redraw->pnt_buf[redraw->num_pnt_buf].index = index;
|
|
redraw->pnt_buf[redraw->num_pnt_buf].color = color;
|
|
++redraw->num_pnt_buf;
|
|
#ifdef PARTITION_FIST
|
|
}
|
|
#endif
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
void AddEdgeToBuffer(redrawdef *redraw, int index1, int index2, int color)
|
|
{
|
|
#ifdef PARTITION_FIST
|
|
#pragma omp critical (edge)
|
|
{
|
|
#endif
|
|
if (redraw->num_edge_buf >= redraw->max_num_edge_buf) {
|
|
redraw->max_num_edge_buf += BLOCK_SIZE;
|
|
redraw->edge_buf =
|
|
(edge_buffer*) ReallocateArray(redraw->memptr,
|
|
redraw->edge_buf,
|
|
redraw->max_num_edge_buf,
|
|
sizeof(edge_buffer),
|
|
"redraw:edge_buf");
|
|
}
|
|
redraw->edge_buf[redraw->num_edge_buf].index1 = index1;
|
|
redraw->edge_buf[redraw->num_edge_buf].index2 = index2;
|
|
redraw->edge_buf[redraw->num_edge_buf].color = color;
|
|
++redraw->num_edge_buf;
|
|
#ifdef PARTITION_FIST
|
|
}
|
|
#endif
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
|
|
void AddTriToBuffer(redrawdef *redraw, int index1, int index2, int index3,
|
|
int color1, int color2)
|
|
{
|
|
#ifdef PARTITION_FIST
|
|
#pragma omp critical (triangle)
|
|
{
|
|
#endif
|
|
int tri_idx;
|
|
#ifdef PARTITION_FIST
|
|
#pragma omp critical (addtri)
|
|
{
|
|
#endif
|
|
if (redraw->num_tri_buf >= redraw->max_num_tri_buf) {
|
|
redraw->max_num_tri_buf += BLOCK_SIZE;
|
|
redraw->tri_buf =
|
|
(tri_buffer*) ReallocateArray(redraw->memptr,
|
|
redraw->tri_buf,
|
|
redraw->max_num_tri_buf,
|
|
sizeof(tri_buffer),
|
|
"redraw:tri_buf");
|
|
}
|
|
#ifdef PARTITION_FIST
|
|
tri_idx = redraw->num_tri_buf;
|
|
++redraw->num_tri_buf;
|
|
}
|
|
#else
|
|
tri_idx = redraw->num_tri_buf;
|
|
++redraw->num_tri_buf;
|
|
#endif
|
|
redraw->tri_buf[tri_idx].index1 = index1;
|
|
redraw->tri_buf[tri_idx].index2 = index2;
|
|
redraw->tri_buf[tri_idx].index3 = index3;
|
|
redraw->tri_buf[tri_idx].color1 = color1;
|
|
redraw->tri_buf[tri_idx].color2 = color2;
|
|
#ifdef PARTITION_FIST
|
|
}
|
|
#endif
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
|
|
void FreeDrawingBuffer(redrawdef *redraw)
|
|
{
|
|
debug_memdef *mem = redraw->memptr;
|
|
FreeMemory(mem, (void**) &redraw->tri_buf, "redraw:tri_buf");
|
|
FreeMemory(mem, (void**) &redraw->edge_buf, "redraw:edge_buf");
|
|
FreeMemory(mem, (void**) &redraw->pnt_buf, "redraw:pnt_buf");
|
|
|
|
redraw->num_pnt_buf = 0;
|
|
redraw->num_edge_buf = 0;
|
|
redraw->num_tri_buf = 0;
|
|
redraw->max_num_pnt_buf = 0;
|
|
redraw->max_num_edge_buf = 0;
|
|
redraw->max_num_tri_buf = 0;
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
|
|
void DecrementPntBuffer(redrawdef *redraw)
|
|
{
|
|
assert(redraw->num_pnt_buf > 0);
|
|
--redraw->num_pnt_buf;
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
void DecrementEdgeBuffer(redrawdef *redraw)
|
|
{
|
|
assert(redraw->num_edge_buf > 0);
|
|
--redraw->num_edge_buf;
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
void ResetTriBuffer(redrawdef *redraw)
|
|
{
|
|
redraw->num_tri_buf = 0;
|
|
|
|
return;
|
|
}
|
|
|
|
#ifdef PARTITION_FIST
|
|
void UpdateTriBuffer(global_struct *all) {
|
|
redrawdef *redraw = &all->c_redraw;
|
|
listdef *list = &all->c_list;
|
|
vertexdef *vertex = &all->c_vertex;
|
|
|
|
ResetTriBuffer(redraw);
|
|
|
|
for(int i = 0; i < vertex->num_triangles; ++i) {
|
|
triangle *tri = &vertex->triangles[i];
|
|
if(!tri->disabled)
|
|
AddTriToBuffer(redraw, GetIndex(list, tri->ind1),
|
|
GetIndex(list, tri->ind2),
|
|
GetIndex(list, tri->ind3),
|
|
TriColor, TriFillColor);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
|
|
void UpdatePntEdgeBuffers(global_struct *all)
|
|
{
|
|
redrawdef *redraw = &all->c_redraw;
|
|
listdef *list = &all->c_list;
|
|
|
|
int i, index1, index2;
|
|
list_ind ind1, ind2;
|
|
|
|
redraw->num_edge_buf = 0;
|
|
redraw->num_pnt_buf = 0;
|
|
|
|
for (i = 0; i < list->num_loops; ++i) {
|
|
ind1 = list->loops[i];
|
|
index1 = GetIndex(list, ind1);
|
|
AddPntToBuffer(redraw, index1, PntsColor);
|
|
ind2 = GetNextNode(list, ind1);
|
|
index2 = GetIndex(list, ind2);
|
|
while (ind2 != ind1) {
|
|
AddPntToBuffer(redraw, index2, PntsColor);
|
|
AddEdgeToBuffer(redraw, index1, index2, PolyColor);
|
|
index1 = index2;
|
|
ind2 = GetNextNode(list, ind2);
|
|
index2 = GetIndex(list, ind2);
|
|
}
|
|
AddEdgeToBuffer(redraw, index1, index2, PolyColor);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
void InitRedrawDefaults(redrawdef *redraw)
|
|
{
|
|
redraw->pnt_buf = (pnt_buffer*) NULL;
|
|
redraw->edge_buf = (edge_buffer*)NULL;
|
|
redraw->tri_buf = (tri_buffer*) NULL;
|
|
|
|
redraw->num_pnt_buf = 0;
|
|
redraw->max_num_pnt_buf = 0;
|
|
redraw->num_edge_buf = 0;
|
|
redraw->max_num_edge_buf = 0;
|
|
redraw->num_tri_buf = 0;
|
|
redraw->max_num_tri_buf = 0;
|
|
}
|
|
|
|
#endif /* GRAPHICS */
|