Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BLI_graph.h « blenlib « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f25db80e95ea5b61b7b9648a38479f400b0aadab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * 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; either version 2
 * of the License, or (at your option) any later version.
 *
 * 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, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * The Original Code is Copyright (C) 2008 Blender Foundation.
 * All rights reserved.
 *
 * Contributor(s): Joshua Leung
 *
 * ***** END GPL LICENSE BLOCK *****
 */
#ifndef __BLI_GRAPH_H__
#define __BLI_GRAPH_H__

/** \file BLI_graph.h
 *  \ingroup bli
 */

#include "DNA_listBase.h"

struct BGraph;
struct BNode;
struct BArc;

struct RadialArc;

typedef void (*FreeArc)(struct BArc *);
typedef void (*FreeNode)(struct BNode *);
typedef void (*RadialSymmetry)(struct BNode *root_node, struct RadialArc *ring, int total);
typedef void (*AxialSymmetry)(struct BNode *root_node, struct BNode *node1, struct BNode *node2, struct BArc *arc1, struct BArc *arc2);

/* IF YOU MODIFY THOSE TYPES, YOU NEED TO UPDATE ALL THOSE THAT "INHERIT" FROM THEM
 *
 * RigGraph, ReebGraph
 *
 * */

typedef struct BGraph {
	ListBase arcs;
	ListBase nodes;
	
	float length;
	
	/* function pointer to deal with custom fonctionnality */
	FreeArc         free_arc;
	FreeNode        free_node;
	RadialSymmetry  radial_symmetry;
	AxialSymmetry   axial_symmetry;
} BGraph;

typedef struct BNode {
	void *next, *prev;
	float p[3];
	int flag;

	int degree;
	struct BArc **arcs;
	
	int subgraph_index;

	int symmetry_level;
	int symmetry_flag;
	float symmetry_axis[3];
} BNode;

typedef struct BArc {
	void *next, *prev;
	struct BNode *head, *tail;
	int flag;

	float length;

	int symmetry_level;
	int symmetry_group;
	int symmetry_flag;
} BArc;

struct BArcIterator;

void *IT_head(void *iter);
void *IT_tail(void *iter);
void *IT_peek(void *iter, int n);
void *IT_next(void *iter);
void *IT_nextN(void *iter, int n);
void *IT_previous(void *iter);
int   IT_stopped(void *iter);

typedef void * (*HeadFct)(void *iter);
typedef void * (*TailFct)(void *iter);
typedef void * (*PeekFct)(void *iter, int n);
typedef void * (*NextFct)(void *iter);
typedef void * (*NextNFct)(void *iter, int n);
typedef void * (*PreviousFct)(void *iter);
typedef int (*StoppedFct)(void *iter);

typedef struct BArcIterator {
	HeadFct head;
	TailFct tail;
	PeekFct peek;
	NextFct next;
	NextNFct nextN;
	PreviousFct previous;
	StoppedFct stopped;
	
	float *p, *no;
	float size;
	
	int length;
	int index;
} BArcIterator;

/* Helper structure for radial symmetry */
typedef struct RadialArc {
	struct BArc *arc; 
	float n[3]; /* normalized vector joining the nodes of the arc */
} RadialArc;

BNode *BLI_otherNode(BArc *arc, BNode *node);

void BLI_freeNode(BGraph *graph, BNode *node);
void BLI_removeNode(BGraph *graph, BNode *node);

void BLI_removeArc(BGraph *graph, BArc *arc);

void BLI_flagNodes(BGraph *graph, int flag);
void BLI_flagArcs(BGraph *graph, int flag);

bool BLI_hasAdjacencyList(BGraph *rg);
void BLI_buildAdjacencyList(BGraph *rg);
void BLI_rebuildAdjacencyListForNode(BGraph *rg, BNode *node);
void BLI_freeAdjacencyList(BGraph *rg);

int BLI_FlagSubgraphs(BGraph *graph);
void BLI_ReflagSubgraph(BGraph *graph, int old_subgraph, int new_subgraph);

#define SHAPE_RADIX 10 /* each shape level is encoded this base */

int BLI_subtreeShape(BGraph *graph, BNode *node, BArc *rootArc, int include_root);
float BLI_subtreeLength(BNode *node);
void BLI_calcGraphLength(BGraph *graph);

void BLI_replaceNode(BGraph *graph, BNode *node_src, BNode *node_replaced);
void BLI_replaceNodeInArc(BGraph *graph, BArc *arc, BNode *node_src, BNode *node_replaced);
void BLI_removeDoubleNodes(BGraph *graph, float limit);
BNode *BLI_FindNodeByPosition(BGraph *graph, const float p[3], const float limit);

BArc  *BLI_findConnectedArc(BGraph *graph, BArc *arc, BNode *v);

bool   BLI_isGraphCyclic(BGraph *graph);

/*------------ Symmetry handling ------------*/
void BLI_markdownSymmetry(BGraph *graph, BNode *root_node, float limit);

void BLI_mirrorAlongAxis(float v[3], float center[3], float axis[3]);

/* BNode symmetry flags */
#define SYM_TOPOLOGICAL 1
#define SYM_PHYSICAL    2

/* the following two are exclusive */
#define SYM_AXIAL       4
#define SYM_RADIAL      8

/* BArc symmetry flags
 *
 * axial symmetry sides */
#define SYM_SIDE_POSITIVE       1
#define SYM_SIDE_NEGATIVE       2
/* Anything higher is the order in radial symmetry */
#define SYM_SIDE_RADIAL         3

#endif /*__BLI_GRAPH_H__*/