Exemplo n.º 1
0
/*
 * Set values and coordinates for each vertex in the grid of CubVtx passed in
 */
void MarchCube::initVertices (int level, 
							  CubeVtx** toSet, 
							  ImpSurface* function)
{
	Point3d lowerLeft(center[0] - sizex / 2.0,
					  center[1] - sizey / 2.0,
					  center[2] - sizez / 2.0);
	lowerLeft[2] += sizez * (level / (Double) resz);

	Double xCoord = lowerLeft[0];
	Double xInc = sizex / (Double) resx;
	Double yInc = sizey / (Double) resy;
	Double zCoord = lowerLeft[2];
	for (int i = 0; i <= resx; ++i)
	{
		Double yCoord = lowerLeft[1];
		for (int j = 0; j <= resy; ++j)
		{
			toSet[i][j].setPos(xCoord, yCoord, zCoord);
			toSet[i][j].setVal(function->eval(toSet[i][j].getPos()));
			yCoord += yInc;
		}
		xCoord += xInc;
	}
}
Exemplo n.º 2
0
DgIVec2D&
DgBoundedRF2D::decrementAddress (DgIVec2D& add) const
{
   if (!validAddress(add) || add == lowerLeft()) return add = invalidAdd();

   if (add.j() == lowerLeft().j())
   {
      add = DgIVec2D(add.i() - 1, upperRight().j());
   }
   else
   {
      add.setJ(add.j() - 1);
   }

   return add;

} // DgIVec2D& DgBoundedRF2D::decrementAddress
Exemplo n.º 3
0
std::uint64_t
DgBoundedRF2D::seqNumAddress (const DgIVec2D& add) const
{
   DgIVec2D tVec = add - lowerLeft();

   std::int64_t sNum = tVec.i() * numJ() + tVec.j();

   if (!zeroBased()) 
    sNum++;

   return sNum;
} // std::uint64_t DgBoundedRF2D::seqNumAddress
Exemplo n.º 4
0
std::auto_ptr<Bempp::Grid> SimpleTriangularGridManager::createGrid()
{
    Bempp::GridParameters params;
    params.topology = Bempp::GridParameters::TRIANGULAR;

    const int dimGrid = 2;
    arma::Col<Bempp::ctype> lowerLeft(dimGrid);
    arma::Col<Bempp::ctype> upperRight(dimGrid);
    arma::Col<unsigned int> nElements(dimGrid);
    lowerLeft.fill(0);
    upperRight.fill(1);
    nElements(0) = N_ELEMENTS_X;
    nElements(1) = N_ELEMENTS_Y;

    return Bempp::GridFactory::createStructuredGrid(params, lowerLeft, upperRight, nElements);
}
Exemplo n.º 5
0
DgIVec2D 
DgBoundedRF2D::addFromSeqNum (std::uint64_t sNum) const
{
   DgIVec2D res;

   if (!zeroBased()) 
    sNum--;

   res.setI(sNum / numJ());
   res.setJ(sNum % numJ());

   res += lowerLeft();

   return res;

} // DgIVec2D DgBoundedRF2D::addFromSeqNum
Exemplo n.º 6
0
DgIVec2D&
DgBoundedRF2D::incrementAddress (DgIVec2D& add) const
{
   if (!validAddress(add)) return add = invalidAdd();
   else if (add == upperRight() || add == endAdd()) return add = endAdd();

   if (add.j() == upperRight().j())
   {
      add = DgIVec2D(add.i() + 1, lowerLeft().j());
   }
   else
   {
      add.setJ(add.j() + 1);
   }

   return add;

} // DgIVec2D& DgBoundedRF2D::incrementAddress
Exemplo n.º 7
0
bool LineIntersectsRect( const DVec2 &v1, const DVec2 &v2, float x, float y, float width, float height )
{
        FVec2 lowerLeft( x, y+height );
        FVec2 upperRight( x+width, y );
        FVec2 upperLeft( x, y );
        FVec2 lowerRight( x+width, y+height);
        // check if it is inside
        if (v1.x > lowerLeft.x && v1.x < upperRight.x && v1.y < lowerLeft.y && v1.y > upperRight.y &&
            v2.x > lowerLeft.x && v2.x < upperRight.x && v2.y < lowerLeft.y && v2.y > upperRight.y )
        {   
            return true;
        }
        // check each line for intersection
        if (LineIntersectLine(v1,v2, upperLeft, lowerLeft ) ) return true;
        if (LineIntersectLine(v1,v2, lowerLeft, lowerRight) ) return true;
        if (LineIntersectLine(v1,v2, upperLeft, upperRight) ) return true;
        if (LineIntersectLine(v1,v2, upperRight, lowerRight) ) return true;
        return false;
}
Exemplo n.º 8
0
/**
 * Main program
 * @param  argc Number of command line arguments, inlucing the program itself.
 * @param  argv Vector of command line arguments.
 * @return      EXIT_SUCCESS if program exits normally, EXIT_ERROR otherwise.
 */
int main(int argc, char** argv) {
  if(argc < 2 || argc > 3) {
    std::cout << "Usage: warper input_image [ouput_image]" << std::endl;
    return EXIT_FAILURE;
  }

  readImage(argv[1]);

  Matrix3x3 M(1.0, 0.0, 0.0,
              0.0, 1.0, 0.0,
              0.0, 0.0, 1.0);
  process_input(M, originalWidth, originalHeight);

  Vector3d upperRight(originalWidth-1,originalHeight-1, 1);
  Vector3d lowerRight(originalWidth-1,0, 1);
  Vector3d upperLeft(0,originalHeight-1, 1);
  Vector3d lowerLeft(0,0, 1);

  upperRight = (M * upperRight)/upperRight[2];
  lowerRight = (M * lowerRight)/lowerRight[2];
  upperLeft = (M * upperLeft)/upperLeft[2];
  lowerLeft = (M * lowerLeft)/lowerLeft[2];

  newWidth = max(max(lowerLeft[0], lowerRight[0]), max(upperLeft[0], upperRight[0]));
  newHeight = max(max(lowerLeft[1], lowerRight[1]), max(upperLeft[1], upperRight[1]));

  int originX = min(min(lowerLeft[0], lowerRight[0]), min(upperLeft[0], upperRight[0]));
  int originY = min(min(lowerLeft[1], upperLeft[1]), min(lowerRight[1], upperRight[1]));

  newHeight = newHeight - originY;
  newWidth = newWidth - originX;

  Vector3d newOrigin(originX, originY, 0);

  // Initalize 2d array
  warppedPixels = new rgba_pixel*[newHeight];
  warppedPixels[0] = new rgba_pixel[newWidth*newHeight];

  for (int i=1; i < newHeight; i++) {
    warppedPixels[i] = warppedPixels[i-1] + newWidth;
  }

  Matrix3x3 invM = M.inv();

  for(int row = 0; row < newHeight; row++)
    for(int col = 0; col < newWidth; col++) {

      Vector3d pixel_out(col, row, 1);
      pixel_out = pixel_out + newOrigin;
      Vector3d pixel_in = invM * pixel_out;

      float u = pixel_in[0] / pixel_in[2];
      float v = pixel_in[1] / pixel_in[2];

      int roundedU = round(u);
      int roundedV = round(v);

      if((0 <= roundedU && roundedU < originalWidth) && (0 <= roundedV && roundedV < originalHeight)) {
          warppedPixels[row][col] = pixels[roundedV][roundedU];
        }
      else {
        rgba_pixel p;
        p.r = 0;
        p.g = 0;
        p.b = 0;
        p.a = 1;
        warppedPixels[row][col] = p;
      }
    }

    // Flip for openGL
    openGLFlip();

    // Init OpenGL
    glutInit(&argc, argv);
    openGLSetup(newWidth, newHeight);

    if(argc == 3) {
      outImage = argv[2];
      writeImage();
    }

    // Start running display window
    glutMainLoop();

  return EXIT_SUCCESS;
}
Exemplo n.º 9
0
bool DecalManager::clipDecal( DecalInstance *decal, Vector<Point3F> *edgeVerts, const Point2F *clipDepth )
{
   PROFILE_SCOPE( DecalManager_clipDecal );

   // Free old verts and indices.
   _freeBuffers( decal );

   ClippedPolyList clipper;

   clipper.mNormal.set( Point3F( 0, 0, 0 ) );
   clipper.mPlaneList.setSize(6);

   F32 halfSize = decal->mSize * 0.5f;
   
   // Ugly hack for ProjectedShadow!
   F32 halfSizeZ = clipDepth ? clipDepth->x : halfSize;
   F32 negHalfSize = clipDepth ? clipDepth->y : halfSize;
   Point3F decalHalfSize( halfSize, halfSize, halfSize );
   Point3F decalHalfSizeZ( halfSizeZ, halfSizeZ, halfSizeZ );

   MatrixF projMat( true );
   decal->getWorldMatrix( &projMat );

   const VectorF &crossVec = decal->mNormal;
   const Point3F &decalPos = decal->mPosition;

   VectorF newFwd, newRight;
   projMat.getColumn( 0, &newRight );
   projMat.getColumn( 1, &newFwd );   

   VectorF objRight( 1.0f, 0, 0 );
   VectorF objFwd( 0, 1.0f, 0 );
   VectorF objUp( 0, 0, 1.0f );

   // See above re: decalHalfSizeZ hack.
   clipper.mPlaneList[0].set( ( decalPos + ( -newRight * halfSize ) ), -newRight );
   clipper.mPlaneList[1].set( ( decalPos + ( -newFwd * halfSize ) ), -newFwd );
   clipper.mPlaneList[2].set( ( decalPos + ( -crossVec * decalHalfSizeZ ) ), -crossVec );
   clipper.mPlaneList[3].set( ( decalPos + ( newRight * halfSize ) ), newRight );
   clipper.mPlaneList[4].set( ( decalPos + ( newFwd * halfSize ) ), newFwd );
   clipper.mPlaneList[5].set( ( decalPos + ( crossVec * negHalfSize ) ), crossVec );

   clipper.mNormal = -decal->mNormal;

   Box3F box( -decalHalfSizeZ, decalHalfSizeZ );

   projMat.mul( box );

   DecalData *decalData = decal->mDataBlock;

   PROFILE_START( DecalManager_clipDecal_buildPolyList );
   getContainer()->buildPolyList( box, decalData->clippingMasks, &clipper );   
   PROFILE_END();

   clipper.cullUnusedVerts();
   clipper.triangulate();
   clipper.generateNormals();
   
   if ( clipper.mVertexList.empty() )
      return false;

#ifdef DECALMANAGER_DEBUG
   mDebugPlanes.clear();
   mDebugPlanes.merge( clipper.mPlaneList );
#endif

   decal->mVertCount = clipper.mVertexList.size();
   decal->mIndxCount = clipper.mIndexList.size();
   
   Vector<Point3F> tmpPoints;

   tmpPoints.push_back(( objFwd * decalHalfSize ) + ( objRight * decalHalfSize ));
   tmpPoints.push_back(( objFwd * decalHalfSize ) + ( -objRight * decalHalfSize ));
   tmpPoints.push_back(( -objFwd * decalHalfSize ) + ( -objRight * decalHalfSize ));
   
   Point3F lowerLeft(( -objFwd * decalHalfSize ) + ( objRight * decalHalfSize ));

   projMat.inverse();

   _generateWindingOrder( lowerLeft, &tmpPoints );

   BiQuadToSqr quadToSquare( Point2F( lowerLeft.x, lowerLeft.y ),
                             Point2F( tmpPoints[0].x, tmpPoints[0].y ), 
                             Point2F( tmpPoints[1].x, tmpPoints[1].y ), 
                             Point2F( tmpPoints[2].x, tmpPoints[2].y ) );  

   Point2F uv( 0, 0 );
   Point3F vecX(0.0f, 0.0f, 0.0f);

   // Allocate memory for vert and index arrays
   _allocBuffers( decal );  
   
   Point3F vertPoint( 0, 0, 0 );

   for ( U32 i = 0; i < clipper.mVertexList.size(); i++ )
   {
      const ClippedPolyList::Vertex &vert = clipper.mVertexList[i];
      vertPoint = vert.point;

      // Transform this point to
      // object space to look up the
      // UV coordinate for this vertex.
      projMat.mulP( vertPoint );

      // Clamp the point to be within the quad.
      vertPoint.x = mClampF( vertPoint.x, -decalHalfSize.x, decalHalfSize.x );
      vertPoint.y = mClampF( vertPoint.y, -decalHalfSize.y, decalHalfSize.y );

      // Get our UV.
      uv = quadToSquare.transform( Point2F( vertPoint.x, vertPoint.y ) );

      const RectF &rect = decal->mDataBlock->texRect[decal->mTextureRectIdx];

      uv *= rect.extent;
      uv += rect.point;      

      // Set the world space vertex position.
      decal->mVerts[i].point = vert.point;
      
      decal->mVerts[i].texCoord.set( uv.x, uv.y );
      
      decal->mVerts[i].normal = clipper.mNormalList[i];
      
      decal->mVerts[i].normal.normalize();

      if( mFabs( decal->mVerts[i].normal.z ) > 0.8f ) 
         mCross( decal->mVerts[i].normal, Point3F( 1.0f, 0.0f, 0.0f ), &vecX );
      else if ( mFabs( decal->mVerts[i].normal.x ) > 0.8f )
         mCross( decal->mVerts[i].normal, Point3F( 0.0f, 1.0f, 0.0f ), &vecX );
      else if ( mFabs( decal->mVerts[i].normal.y ) > 0.8f )
         mCross( decal->mVerts[i].normal, Point3F( 0.0f, 0.0f, 1.0f ), &vecX );
   
      decal->mVerts[i].tangent = mCross( decal->mVerts[i].normal, vecX );
   }

   U32 curIdx = 0;
   for ( U32 j = 0; j < clipper.mPolyList.size(); j++ )
   {
      // Write indices for each Poly
      ClippedPolyList::Poly *poly = &clipper.mPolyList[j];                  

      AssertFatal( poly->vertexCount == 3, "Got non-triangle poly!" );

      decal->mIndices[curIdx] = clipper.mIndexList[poly->vertexStart];         
      curIdx++;
      decal->mIndices[curIdx] = clipper.mIndexList[poly->vertexStart + 1];            
      curIdx++;
      decal->mIndices[curIdx] = clipper.mIndexList[poly->vertexStart + 2];                
      curIdx++;
   } 

   if ( !edgeVerts )
      return true;

   Point3F tmpHullPt( 0, 0, 0 );
   Vector<Point3F> tmpHullPts;

   for ( U32 i = 0; i < clipper.mVertexList.size(); i++ )
   {
      const ClippedPolyList::Vertex &vert = clipper.mVertexList[i];
      tmpHullPt = vert.point;
      projMat.mulP( tmpHullPt );
      tmpHullPts.push_back( tmpHullPt );
   }

   edgeVerts->clear();
   U32 verts = _generateConvexHull( tmpHullPts, edgeVerts );
   edgeVerts->setSize( verts );

   projMat.inverse();
   for ( U32 i = 0; i < edgeVerts->size(); i++ )
      projMat.mulP( (*edgeVerts)[i] );

   return true;
}