Commit 4edf9336 authored by Célestin Marot's avatar Célestin Marot
Browse files

small bug solved

parent be34cb12
# compilation and linking flags
CFLAGS=-Wall -Wextra -O3
CFLAGS=-Wall -Wextra -O3 -g
LDFLAGS=-lm
# directories
......@@ -8,17 +8,26 @@ OBJDIR=.cache
BINDIR=bin
# targets
EXE=$(BINDIR)/test
SRC=$(wildcard $(SRCDIR)/*.c)
OBJ=$(SRC:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
EXE0=$(BINDIR)/test
EXE1=$(BINDIR)/benchmark
OBJ0=$(filter-out $(OBJDIR)/benchmark.o, $(OBJ))
OBJ1=$(filter-out $(OBJDIR)/test.o, $(OBJ))
$(EXE): $(OBJ) | $(BINDIR)
all: $(EXE0) $(EXE1)
$(EXE0): $(OBJ0) | $(BINDIR)
$(EXE1): $(OBJ1) | $(BINDIR)
$(EXE0) $(EXE1):
$(CC) -o $@ $^ $(LDFLAGS)
# additional dependencies to headers
$(OBJDIR)/predicates.o: $(SRCDIR)/predicates.h
$(OBJDIR)/HXTSPR.o: $(SRCDIR)/HXTSPR.h $(SRCDIR)/predicates.h
$(OBJDIR)/test.o: $(SRCDIR)/HXTSPR.h
$(OBJDIR)/benchmark.o: $(SRCDIR)/HXTSPR.h
$(OBJ): $(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR)
# @echo $@ depends on $^
......@@ -33,4 +42,4 @@ help:
clean:
rm -rf .cache out.msh
.PHONY: help clean
.PHONY: all help clean
......@@ -75,11 +75,11 @@ points of the basic algorithm, namely the choice of *the digging face* and
*the order of candidate nodes*. However, our new implementation brings a few
novelties:
- **the digging face** is not only chosen to have the worst quality, it also
- **The digging face** is not only chosen to have the worst quality, it also
has the least number of possible tetrahedra. In addition, the quality measure
can be a totally arbitrary user-defined function. In comparison, Liu et al.
use measure of angles that won't work with anysotropic meshes.
- **the order of candidate nodes** is chosen regarding multiple criteria that
- **The order of candidate nodes** is chosen regarding multiple criteria that
are very different from Liu et al. A candidate node has is chosen in priority
if:
- It is the opposite node in one, two or all adjacent triangles
......@@ -93,7 +93,7 @@ novelties:
Because those worst cavities will generally take 99% of a program time, we
can safely say that this optimization alone makes this implementation far
better.
- **open-source implementation** All the commented source code
- **Open-source implementation** All the commented source code
of the SPR function lie in this repository.
## Documentation
......@@ -112,9 +112,9 @@ The exact predicates of J.R. Shewchuk have seen a few improvements to make this
library thread-safe and also such that you can call `exactinit()` in other parts
of your code.
## build test example in .5s
## build test example
make -j3
make -j4
## run and see output
......
......@@ -23,6 +23,8 @@ Author: Célestin Marot (celestin.marot@uclouvain.be) */
#include <math.h>
#include <assert.h>
// #define SPR_RECURSIVE_VERSION
#ifdef _MSC_VER
#define SPRNOINLINE __declspec(noinline)
......@@ -746,8 +748,7 @@ static inline uint16_t best_face_heuristic(SPRCavity* SPR, double* qualMax)
#ifdef SPR_USE_FACE_HEURISTIC
const uint8_t npts = SPR->points.num;
int worstNumValid = 255;
double worstQualSum = DBL_MAX;
int minValid = 255;
uint16_t worstFaceID = UINT16_MAX;
double minimax = DBL_MAX;
......@@ -757,10 +758,9 @@ static inline uint16_t best_face_heuristic(SPRCavity* SPR, double* qualMax)
SPRTet tet = SPR->triangles.array[triangleID];
int numValid = 0;
double qualSum = 0.0;
double max = 0.0;
for (tet.node[3]=0; tet.node[3] < npts && numValid <= worstNumValid; tet.node[3]++)
for (tet.node[3]=0; tet.node[3] < npts && numValid<minValid; tet.node[3]++)
{
if(tet.node[3] == tet.node[0] ||
tet.node[3] == tet.node[1] ||
......@@ -780,22 +780,16 @@ static inline uint16_t best_face_heuristic(SPRCavity* SPR, double* qualMax)
max = qual;
numValid++;
qualSum += qual;
}
if(numValid==0)
if(numValid<1)
return UINT16_MAX;
if(max < minimax)
minimax = max;
if(numValid <= worstNumValid) {
worstNumValid = numValid;
worstQualSum = qualSum;
worstFaceID = triangleID;
}
else if(numValid==worstNumValid && qualSum<worstQualSum) {
worstQualSum = qualSum;
if(numValid < minValid) {
minValid = numValid;
worstFaceID = triangleID;
}
}
......@@ -1131,7 +1125,6 @@ static inline void SPR_terminate(SPRCavity* SPR)
int hxtSPR(SPRCavity* SPR)
{
SPRExact valuesOnStack; // structure needed for the exact predicates to work
SPR->values = &valuesOnStack;
if(SPR_init(SPR))
return 2;
......@@ -1355,6 +1348,8 @@ void hxtSPR_recur(SPRCavity* SPR) {
int hxtSPR(SPRCavity* SPR) {
SPRExact valuesOnStack; // structure needed for the exact predicates to work
SPR->values = &valuesOnStack;
if(SPR_init(SPR))
return 2;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment