forked from t3kt/DistThresholdCHOP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLineSet.cpp
52 lines (47 loc) · 1.29 KB
/
LineSet.cpp
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
#include "LineSet.h"
LineSet::~LineSet()
{
for( int part = 0; part < NUM_OUTS; part++ )
free( partBuffers[part] );
}
void LineSet::reset( int max )
{
numLines = 0;
if( max <= 0 )
max = 1;
// if the new max is different than the old max, realloc()
// the first time this is called, buffer == NULL, so this is just like malloc()
if( max != maxLines )
{
maxLines = max;
for( int part = 0; part < NUM_OUTS; part++ )
{
partBuffers[part] = (float*)realloc(partBuffers[part], max * NUM_OUTS * sizeof(float));
}
}
}
bool LineSet::addLine( const InputPoint p1, const InputPoint p2, const float sqrDist )
{
if( numLines >= maxLines )
return false;
partBuffers[OUT_TX1][numLines] = p1.x;
partBuffers[OUT_TY1][numLines] = p1.y;
partBuffers[OUT_TZ1][numLines] = p1.z;
partBuffers[OUT_TX2][numLines] = p2.x;
partBuffers[OUT_TY2][numLines] = p2.y;
partBuffers[OUT_TZ2][numLines] = p2.z;
partBuffers[OUT_SQRDIST][numLines] = sqrDist;
#ifdef INCLUDE_INDEX_OUTPUTS
partBuffers[OUT_INDEX1][numLines] = (float)p1.index;
partBuffers[OUT_INDEX2][numLines] = (float)p2.index;
#endif
numLines++;
return true;
}
void LineSet::copyTo( const CHOP_Output* output ) const
{
for( int part = 0; part < NUM_OUTS; part++ )
{
memcpy( output->channels[part], partBuffers[part], numLines * sizeof(float) );
}
}