[Bf-blender-cvs] [be72ad6] gooseberry: Simplified data structure and reading code for strands in Alembic caches.

Lukas Tönne noreply at git.blender.org
Wed Mar 25 15:19:46 CET 2015


Commit: be72ad615a68c48d27ad615d5de0f30fc93778f5
Author: Lukas Tönne
Date:   Wed Mar 25 15:08:02 2015 +0100
Branches: gooseberry
https://developer.blender.org/rBbe72ad615a68c48d27ad615d5de0f30fc93778f5

Simplified data structure and reading code for strands in Alembic
caches.

===================================================================

M	source/blender/blenkernel/BKE_strands.h
M	source/blender/blenkernel/intern/strands.c
M	source/blender/pointcache/alembic/abc_particles.cpp

===================================================================

diff --git a/source/blender/blenkernel/BKE_strands.h b/source/blender/blenkernel/BKE_strands.h
index 950df1c..22e9c4b 100644
--- a/source/blender/blenkernel/BKE_strands.h
+++ b/source/blender/blenkernel/BKE_strands.h
@@ -21,28 +21,20 @@
 
 #include "BLI_utildefines.h"
 
-#define STRANDS_BLOCK_SIZE                          (1 << 14) /* 16384 */
-#define STRANDS_INDEX_TO_BLOCK(i)                   ((i) >> 14)
-#define STRANDS_INDEX_TO_BLOCK_OFFSET(i)            ((i) - STRANDS_INDEX_TO_BLOCK((i)))
-#define STRANDS_BLOCK_TO_INDEX(block, offset)       ((block) * STRANDS_BLOCK_SIZE + (offset))
-
-typedef struct StrandsVertexBlock {
-	float co[STRANDS_BLOCK_SIZE][3];
-	float vel[STRANDS_BLOCK_SIZE][3];
-	float rot[STRANDS_BLOCK_SIZE][4];
-	float col[STRANDS_BLOCK_SIZE][3];
-	float time[STRANDS_BLOCK_SIZE];
-} StrandsVertexBlock;
-
-typedef struct StrandsBlock {
-	int numverts[STRANDS_BLOCK_SIZE];
-	int parent[STRANDS_BLOCK_SIZE];
-} StrandsBlock;
+typedef struct StrandsVertex {
+	float co[3];
+	float time;
+	float weight;
+} StrandsVertex;
+
+typedef struct StrandsCurve {
+	int numverts;
+} StrandsCurve;
 
 typedef struct Strands {
-	StrandsBlock *strands;
-	StrandsVertexBlock *verts;
-	int totstrands, totverts;
+	StrandsCurve *curves;
+	StrandsVertex *verts;
+	int totcurves, totverts;
 } Strands;
 
 struct Strands *BKE_strands_new(int strands, int verts);
@@ -50,83 +42,55 @@ void BKE_strands_free(struct Strands *strands);
 
 /* ------------------------------------------------------------------------- */
 
-#if 0
-typedef struct StrandsIterator {
-	int totstrands; /* total number of strands to loop over */
-	int strand_index, strand_block; /* index of current strand and index in the block */
-	int vertex_start, vertex_block_next;
-	
-	int *numverts, *parent;
-} StrandsIterator;
+typedef struct StrandIterator {
+	int index, tot;
+	StrandsCurve *curve;
+	StrandsVertex *verts;
+} StrandIterator;
 
-BLI_INLINE void BKE_strands_iter_init(StrandsIterator *iter, Strands *strands)
+BLI_INLINE void BKE_strand_iter_init(StrandIterator *iter, Strands *strands)
 {
-	iter->strand_index = 0;
-	iter->strand_block = 0;
-	iter->totstrands = strands->totstrands;
-	
-	iter->vertex_start = 0;
-	iter->vertex_block_next = 0;
-	
-	iter->numverts = strands->strands->numverts;
-	iter->parent = strands->strands->parent;
+	iter->tot = strands->totcurves;
+	iter->index = 0;
+	iter->curve = strands->curves;
 }
 
-BLI_INLINE bool BKE_strands_iter_valid(StrandsIterator *iter)
+BLI_INLINE bool BKE_strand_iter_valid(StrandIterator *iter)
 {
-	return (iter->strand_index < iter->totstrands);
+	return iter->index < iter->tot;
 }
 
-BLI_INLINE void BKE_strand_iter_next(StrandsIterator *iter)
+BLI_INLINE void BKE_strand_iter_next(StrandIterator *iter)
 {
-	int numverts = *iter->numverts;
-	
-	++iter->strand_index;
-	++iter->strand_block;
-	if (iter->strand_block > STRANDS_BLOCK_SIZE)
-		iter->strand_block -= STRANDS_BLOCK_SIZE;
+	const int numverts = iter->curve->numverts;
 	
-	iter->vertex_start += numverts;
-	iter->vertex_block_next += numverts;
-	if (iter->vertex_block_next > STRANDS_BLOCK_SIZE)
-		iter->vertex_block_next = 0;
+	++iter->index;
+	++iter->curve;
+	iter->verts += numverts;
 }
-#endif
 
 
-#if 0
-typedef struct StrandsIterator {
-	int strand_index, vertex_index;
-	int strand_block, vertex_block;
-	int totstrands, totverts;
-	float *co[3], *vel[3], *rot[4], *col[3], *time;
-} StrandsIterator;
+typedef struct StrandVertexIterator {
+	int index, tot;
+	StrandsVertex *vertex;
+} StrandVertexIterator;
 
-BLI_INLINE void BKE_strands_iter_init(StrandsIterator *iter, Strands *strands)
+BLI_INLINE void BKE_strand_vertex_iter_init(StrandVertexIterator *iter, StrandIterator *strand_iter)
 {
-	iter->strand_index = 0;
-	iter->strand_block = 0;
-	iter->totstrands = strands->totstrands;
-	iter->totverts = strands->totverts;
-	iter->vertex_index = 0;
-	iter->vertex_block = 0;
-	iter->co = strands->verts->co;
-	iter->vel = strands->verts->vel;
-	iter->rot = strands->verts->rot;
-	iter->col = strands->verts->col;
-	iter->time = strands->verts->time;
+	iter->tot = strand_iter->curve->numverts;
+	iter->index = 0;
+	iter->vertex = strand_iter->verts;
 }
 
-BLI_INLINE bool BKE_strands_iter_valid(StrandsIterator *iter)
+BLI_INLINE bool BKE_strand_vertex_iter_valid(StrandVertexIterator *iter)
 {
-	return (iter->strand_index < iter->totstrands) && (iter->vertex_index < iter->totverts);
+	return iter->index < iter->tot;
 }
 
-BLI_INLINE void BKE_strand_iter_next(StrandsIterator *iter)
+BLI_INLINE void BKE_strand_vertex_iter_next(StrandVertexIterator *iter)
 {
-	++iter->vertex_index;
-	++iter->vertex_block;
+	++iter->vertex;
+	++iter->index;
 }
-#endif
 
 #endif  /* __BKE_STRANDS_H__ */
diff --git a/source/blender/blenkernel/intern/strands.c b/source/blender/blenkernel/intern/strands.c
index 7fcfc88..8130382 100644
--- a/source/blender/blenkernel/intern/strands.c
+++ b/source/blender/blenkernel/intern/strands.c
@@ -20,18 +20,15 @@
 
 #include "BKE_strands.h"
 
-Strands *BKE_strands_new(int strands, int verts)
+Strands *BKE_strands_new(int curves, int verts)
 {
-	int num_strand_blocks = STRANDS_INDEX_TO_BLOCK(strands);
-	int num_vertex_blocks = STRANDS_INDEX_TO_BLOCK(verts);
-	
 	Strands *s = MEM_mallocN(sizeof(Strands), "strands");
 	
-	s->totstrands = strands;
-	s->strands = MEM_mallocN(sizeof(StrandsBlock) * num_strand_blocks, "strand strands");
+	s->totcurves = curves;
+	s->curves = MEM_mallocN(sizeof(StrandsCurve) * curves, "strand curves");
 	
 	s->totverts = verts;
-	s->verts = MEM_mallocN(sizeof(StrandsVertexBlock) * num_vertex_blocks, "strand vertices");
+	s->verts = MEM_mallocN(sizeof(StrandsVertex) * verts, "strand vertices");
 	
 	return s;
 }
@@ -39,8 +36,8 @@ Strands *BKE_strands_new(int strands, int verts)
 void BKE_strands_free(Strands *strands)
 {
 	if (strands) {
-		if (strands->strands)
-			MEM_freeN(strands->strands);
+		if (strands->curves)
+			MEM_freeN(strands->curves);
 		if (strands->verts)
 			MEM_freeN(strands->verts);
 		MEM_freeN(strands);
diff --git a/source/blender/pointcache/alembic/abc_particles.cpp b/source/blender/pointcache/alembic/abc_particles.cpp
index 41e1f0b..43f7e19 100644
--- a/source/blender/pointcache/alembic/abc_particles.cpp
+++ b/source/blender/pointcache/alembic/abc_particles.cpp
@@ -261,17 +261,37 @@ PTCReadSampleResult AbcStrandsReader::read_sample(float frame)
 	ICurvesSchema::Sample sample;
 	schema.get(sample, ss);
 	
-	P3fArraySamplePtr positions = sample.getPositions();
-	Int32ArraySamplePtr nvertices = sample.getCurvesNumVertices();
+	P3fArraySamplePtr sample_co = sample.getPositions();
+	Int32ArraySamplePtr sample_numvert = sample.getCurvesNumVertices();
 	IFloatGeomParam::Sample sample_time = m_param_times.getExpandedValue(ss);
 	IFloatGeomParam::Sample sample_weight = m_param_weights.getExpandedValue(ss);
 	
-	if (!positions || !nvertices)
+	if (!sample_co || !sample_numvert)
 		return PTC_READ_SAMPLE_INVALID;
 	
-	m_strands = BKE_strands_new(nvertices->size(), positions->size());
-//	paths_apply_sample_nvertices(*m_pathcache, *m_totpath, nvertices);
-//	paths_apply_sample_data(*m_pathcache, *m_totpath, positions, sample_vel.getVals(), sample_rot.getVals(), sample_col.getVals(), sample_time.getVals());
+	m_strands = BKE_strands_new(sample_numvert->size(), sample_co->size());
+	
+	const int32_t *numvert = sample_numvert->get();
+	for (int i = 0; i < sample_numvert->size(); ++i) {
+		StrandsCurve *scurve = &m_strands->curves[i];
+		scurve->numverts = *numvert;
+		
+		++numvert;
+	}
+	
+	const V3f *co = sample_co->get();
+	const float32_t *time = sample_time.getVals()->get();
+	const float32_t *weight = sample_weight.getVals()->get();
+	for (int i = 0; i < sample_co->size(); ++i) {
+		StrandsVertex *svert = &m_strands->verts[i];
+		copy_v3_v3(svert->co, co->getValue());
+		svert->time = *time;
+		svert->weight = *weight;
+		
+		++co;
+		++time;
+		++weight;
+	}
 	
 	return PTC_READ_SAMPLE_EXACT;
 }




More information about the Bf-blender-cvs mailing list