MCPcopy Create free account
hub / github.com/ImageEngine/cortex / PointDistribution

Method PointDistribution

src/IECore/PointDistribution.cpp:12–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10using namespace IECore;
11
12PointDistribution::PointDistribution( const std::string &tileSet )
13 : m_numSubTiles( 0 )
14{
15 std::ifstream f( tileSet.c_str(), std::ios_base::binary | std::ios_base::in );
16 if( f.fail() || !f.is_open() )
17 {
18 throw IOException( "Unable to open file." );
19 }
20
21 // read the header
22 //////////////////
23
24 int numTiles = 0;
25 f.read( (char *)&numTiles, sizeof( numTiles ) );
26
27 f.read( (char *)&m_numSubTiles, sizeof( m_numSubTiles ) );
28
29 // the subdivs is unused here. the example code to accompany the
30 // paper always indexes subdivs[0] in recurseTile() so it seems unclear
31 // what to do with more subdivs if they existed.
32 int subdivs = 0;
33 f.read( (char *)&subdivs, sizeof( subdivs ) );
34 assert( subdivs==1 );
35
36 // read each tile
37 /////////////////
38
39 m_tiles.resize( numTiles );
40 for( int i=0; i<numTiles; i++ )
41 {
42 Tile &tile = m_tiles[i];
43
44 // wang colors
45 f.read( (char *)&tile.n, sizeof( tile.n ) );
46 f.read( (char *)&tile.e, sizeof( tile.e ) );
47 f.read( (char *)&tile.s, sizeof( tile.s ) );
48 f.read( (char *)&tile.w, sizeof( tile.w ) );
49 tile.n = tile.n % 2; // the cohen et al tileset is actually made up of two rather than four colors,
50 tile.s = tile.s % 2; // as green/red is exclusively north/south and yellow/blue is exclusively east/west
51
52 // pointers to subtiles
53 const int subTilesSqr = m_numSubTiles * m_numSubTiles;
54 tile.subTiles.resize( subTilesSqr );
55 for( int j=0; j<subTilesSqr; j++ )
56 {
57 int subTileIndex = 0;
58 f.read( (char *)&subTileIndex, sizeof( subTileIndex ) );
59 tile.subTiles[j] = &(m_tiles[subTileIndex]);
60 }
61
62 // points
63 int numPoints = 0;
64 f.read( (char *)&numPoints, sizeof( numPoints ) );
65 tile.points.resize( numPoints );
66 for( int j=0; j<numPoints; j++ )
67 {
68 f.read( (char *)&(tile.points[j]), sizeof( Imath::V2f ) );
69 f.seekg( sizeof( int ) * 4, std::ios_base::cur ); // skip chunk of unknown data, presumably used during the tile generation process?

Callers

nothing calls this directly

Calls 7

IOExceptionFunction · 0.85
seekgMethod · 0.80
copyFunction · 0.70
readMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected