Пример #1
0
typename Field2<NUMCOMPONENTS>::DataType
Field2<NUMCOMPONENTS>::node(const card32 i_, const card32 j_) const {
  DataType out;
  for(size_t k=0; k<NUMCOMPONENTS; ++k)
    out[k] = mGridData.data[NUMCOMPONENTS*linearIndex(i_, j_) + k];
  return out;
}
Пример #2
0
typename Field2<NUMCOMPONENTS>::DataType
Field2<NUMCOMPONENTS>::sample(const PosType &x_) const {
  assert(mGridData.data.size());

  //check bounds
  if(!insideBounds(x_))
    return DataType().setZero();

  //get uniform parametrization location
  PosType localPos;
  localPos[0] = (x_[0] - mGridData.boundMin[0]) * mInvScaleFactor[0];
  localPos[1] = (x_[1] - mGridData.boundMin[1]) * mInvScaleFactor[1];

  //get grid indices
  const card32  i0 = card32(std::floor(localPos[0])),
                j0 = card32(std::floor(localPos[1]));

  const card32  i1 = min(mGridData.dims[0]-1, i0+1),
                j1 = min(mGridData.dims[1]-1, j0+1);

  //get uniform parametrization
  const float32 u = localPos[0] - float32(i0),
                v = localPos[1] - float32(j0);

  //perform bilinear interpolation for each data component
  const float32 b00 = (1-u)*(1-v),
                b10 =     u*(1-v),
                b01 = (1-u)*v,
                b11 =     u*v;

  DataType out;

  for(size_t k=0; k<NUMCOMPONENTS; ++k)
    out[k] = b00 * mGridData.data[NUMCOMPONENTS*linearIndex(i0, j0) + k] +
             b10 * mGridData.data[NUMCOMPONENTS*linearIndex(i1, j0) + k] +
             b01 * mGridData.data[NUMCOMPONENTS*linearIndex(i0, j1) + k] +
             b11 * mGridData.data[NUMCOMPONENTS*linearIndex(i1, j1) + k];

  return out;
}
Пример #3
0
int TileIndex::indexLon(const int getLevel) const
{
    return linearIndex(getLevel) % Tiling;
}
Пример #4
0
int TileIndex::indexLat(const int getLevel) const
{
    return linearIndex(getLevel) / Tiling;
}
Пример #5
0
/// Set the mask flag of the detector with given index. Not thread safe.
void DetectorInfo::setMasked(const std::pair<size_t, size_t> &index,
                             bool masked) {
  m_isMasked.access()[linearIndex(index)] = masked;
}
Пример #6
0
/// Returns true if the detector with given index is masked.
bool DetectorInfo::isMasked(const std::pair<size_t, size_t> &index) const {
  return (*m_isMasked)[linearIndex(index)];
}
MStatus genRod(
	const MPoint &p0,
	const MPoint &p1,
	const double radius,
	const unsigned int nSegs,
	
	int &nPolys,
	MPointArray &verts,
	MIntArray &polyCounts,
	MIntArray &polyConnects
)
{
	verts.clear();
	polyCounts.clear();
	polyConnects.clear();
	
	unsigned int nCirclePts = nSegs; 
	unsigned int nVerts = 2 * nCirclePts;
	
	// Calculate the local axiis of the rod
	MVector vec( p1 - p0 );
	MVector up( 0.0, 1.0, 0.0 );
	MVector xAxis, yAxis, zAxis;
	
	yAxis = vec.normal();
	if( up.isParallel( yAxis, 0.1 ) )
		up = MVector( 1.0, 0.0, 0.0 );
	xAxis = yAxis ^ up;
	zAxis = (xAxis ^ yAxis).normal();
	xAxis = (yAxis ^ zAxis ).normal(); 
	
	// Calculate the vertex positions
	verts.setLength( nVerts );
	double angleIncr = 2.0 * M_PI / nSegs;
	double angle;
	MPoint p;
	double x, z;
	unsigned int i;
	for( i=0, angle=0; i < nCirclePts; i++, angle += angleIncr )
	{
		// Calculate position in circle
		x = radius * cos( angle );
		z = radius * sin( angle );
		
		p = p0 + x * xAxis + z * zAxis;

		verts[ i ] = p;
		
		p += vec;

		verts[ i + nCirclePts ] = p;
	}
	
	nPolys = nSegs;
	
	// Generate polycounts
	polyCounts.setLength( nPolys );
	for( i=0; i < polyCounts.length(); i++ )
		polyCounts[i] = 4;
	
	// Generate polyconnects
	polyConnects.setLength( nPolys * 4 );
	polyConnects.clear();
	for( i=0; i < nSegs; i++ )
	{
		polyConnects.append( linearIndex( 0, i, 2, nCirclePts ) );
		polyConnects.append( linearIndex( 0, i+1, 2, nCirclePts ) );
		polyConnects.append( linearIndex( 1, i+1, 2, nCirclePts ) );
		polyConnects.append( linearIndex( 1, i, 2, nCirclePts ) );
	}
		
	return MS::kSuccess;
}
MStatus genBall( 
	const MPoint &centre,
	const double radius,
	const unsigned int nSegs,
	
	int &nPolys,
	MPointArray &verts,
	MIntArray &polyCounts,
	MIntArray &polyConnects
)	
{
	verts.clear();
	polyCounts.clear();
	polyConnects.clear();
	
	int nAzimuthSegs = nSegs * 2;
	int nZenithSegs = nSegs;
	
	int nAzimuthPts = nAzimuthSegs; // Last point corresponds to the first
	int nZenithPts = nZenithSegs + 1; // Last point is at other pole
	
	
	double azimIncr = 2.0 * M_PI / nAzimuthSegs;
	double zenIncr = M_PI / nZenithSegs;
	
	MPoint p;
	double azimuth, zenith;
	double sinZenith;
	int azi, zeni;
	
	zenith = 0.0;
	for( zeni=0; zeni < nZenithPts; zeni++, zenith += zenIncr )
	{
		azimuth = 0.0;
		for( azi=0; azi < nAzimuthPts; azi++, azimuth += azimIncr )
		{
			sinZenith = sin(zenith);
			
			p.x = radius * sinZenith * cos(azimuth);
			p.y = radius * cos(zenith);
			p.z = radius * sinZenith * sin(azimuth);
		
			verts.append( p );
		}
	}
	
	// Calculate the number of polygons
	nPolys = nAzimuthSegs * nZenithSegs;
	
	// Each face has four points
	polyCounts.setLength( nPolys );
	int i;
	for( i=0; i < nPolys; i++ )
		polyCounts[i] = 4;
	
	// Generate the faces
	for( zeni=0; zeni < nZenithSegs; zeni++ )
	{
		for( azi=0; azi < nAzimuthSegs; azi++ )
		{
			//MGlobal::displayInfo( MString( "\n" ) + azi + "," + zeni );
			
			polyConnects.append( linearIndex( zeni, azi, nZenithPts, nAzimuthPts ) );
			polyConnects.append( linearIndex( zeni, azi+1, nZenithPts, nAzimuthPts ) );
			polyConnects.append( linearIndex( zeni+1, azi+1, nZenithPts, nAzimuthPts ) );
			polyConnects.append( linearIndex( zeni+1, azi, nZenithPts, nAzimuthPts ) );
		}
	}	
	
	return MS::kSuccess;
}
Пример #9
0
void Field2<NUMCOMPONENTS>::setNode(const card32 i_, const card32 j_,
                                    DataType data_) {
  for(size_t k=0; k<NUMCOMPONENTS; ++k)
    mGridData.data[NUMCOMPONENTS*linearIndex(i_, j_) + k] = data_[k];
}