Пример #1
0
bool ray4::hitsAABB(const float4 &min, const float4 &max, float4 &position) const
{
    uint4 startSmallerMin = (start() < min);
    uint4 startBiggerMax = (start() > max);

    if(!(startSmallerMin || startBiggerMax).any())
    {
        position = start();
        return true;
    }

    float4 dir = direction();
    uint4 dirNotNull = (dir != 0);
    float4 maxT(-1.0f);

    position = startSmallerMin.select(min, position);
    position = startBiggerMax.select(max, position);
    maxT = (startSmallerMin && dirNotNull).select((min - start()) / dir, maxT);
    maxT = (startBiggerMax && dirNotNull).select((max - start()) / dir, maxT);

    if(maxT.max() < 0.0f)
        return false;

    position = point(maxT.max());

    if(((position > max) || (position < min)).any())
        return false;

    return true;
}
Пример #2
0
int maxszer(drzewo d)
{
    int szer, wys = wysokosc(d) + 1;
    int* t = calloc(wys, sizeof(int));
    pomszer(d, t, 0);
    szer = maxT(t, wys);
    free(t);
    return szer;
}
    Intersection intersect( const Ray &one, const AxisAlignedBox &two )
    {
        // Null box?
        if (two.isNull()) return OUTSIDE;
	    // Infinite box?
	    if (two.isInfinite()) return INTERSECT;

        bool inside = true;
        const Vector3& twoMin = two.getMinimum();
        const Vector3& twoMax = two.getMaximum();
        Vector3 origin = one.getOrigin();
        Vector3 dir = one.getDirection();

        Vector3 maxT(-1, -1, -1);

        int i = 0;
        for(i=0; i<3; i++ )
        {
            if( origin[i] < twoMin[i] )
            {
                inside = false;
                if( dir[i] > 0 )
                {
                    maxT[i] = (twoMin[i] - origin[i])/ dir[i];
                }
            }
            else if( origin[i] > twoMax[i] )
            {
                inside = false;
                if( dir[i] < 0 )
                {
                    maxT[i] = (twoMax[i] - origin[i]) / dir[i];
                }
            }
        }

        if( inside )
        {
            return INTERSECT;
        }
        int whichPlane = 0;
        if( maxT[1] > maxT[whichPlane])
            whichPlane = 1;
        if( maxT[2] > maxT[whichPlane])
            whichPlane = 2;

        if( ((int)maxT[whichPlane]) & 0x80000000 )
        {
            return OUTSIDE;
        }
        for(i=0; i<3; i++ )
        {
            if( i!= whichPlane )
            {
                float f = origin[i] + maxT[whichPlane] * dir[i];
                if ( f < (twoMin[i] - 0.00001f) ||
                        f > (twoMax[i] +0.00001f ) )
                {
                    return OUTSIDE;
                }
            }
        }

        return INTERSECT;

    }
Пример #4
0
/**
 * @brief PermTestingCPU
 * @details 
 *         See PermTesting.h for information
 */
arma::mat TwoSamplePermTestingCPU(arma::mat data, 
                                  int nPermutations,
                                  int nGroup1, 
                                  double maxMemory)
{
    std::string path1 = "/Users/felipegb94/PermTest/data/raw_adrc/permutationMatrix1.arma";
    std::string path2 = "/Users/felipegb94/PermTest/data/raw_adrc/permutationMatrix2.arma";
    std::cout << "Starting PermTestingMatrix..." << std::endl;
    int N; // Total number of subjects
    int nGroup2; // Total number of subjects in group 2
    int V; // Total number of statistics/voxels to be tested
    int nPermutationsPerIteration; // Number of permutations done at once
    int numIterations; // nPermutations/nPermutationsPerIteration
    int lastIteration;
    int start, end; // Start and end of current interval

    arma::cube permutationMatrices;
    arma::mat permutationMatrix1;
    arma::mat permutationMatrix2; 
    arma::mat maxT; // Maximum null distribution
    arma::mat dataSquared;
    arma::mat g1Mean;
    arma::mat g2Mean;
    arma::mat g1Var;
    arma::mat g2Var;
    arma::mat tStatMatrix;

    /* Set constant values and allocate memory */   
    N = data.n_rows; 
    V = data.n_cols;
    nGroup2 = N - nGroup1;
    std::cout << "testing GetPerm " <<std::endl;
    permutationMatrices = TwoSampleGetPermutationMatrices(nPermutations, N, nGroup1);
    std::cout << "testing GetPerm " <<std::endl;

    permutationMatrix1 = permutationMatrices.slice(0);
    permutationMatrix2 = permutationMatrices.slice(1);
    dataSquared = data % data;
    nPermutationsPerIteration = GetIntervalDimension(V, maxMemory);
    lastIteration = nPermutations % nPermutationsPerIteration;
    numIterations = floor(nPermutations/nPermutationsPerIteration);
    maxT = arma::zeros(nPermutations,1);


    std::cout << "Number of subjects (rows in data matrix): " << N << std::endl;
    std::cout << "Number of voxels per subject (cols in data matrix and cols in indexMatrix): ";
    std::cout << V << std::endl;
    std::cout << "Number of Permutations (rows in permutations matrix):" << nPermutations << std::endl;
    std::cout << "Size of group1 = " << nGroup1 << std::endl;
    std::cout << "Size of group2 = " << nGroup2 << std::endl;
    std::cout << "Rows in PermutationMatrices = " << permutationMatrices.n_rows << std::endl;
    std::cout << "Cols in PermutationMatrices = " << permutationMatrices.n_cols << std::endl;
    std::cout << "Interval Size = " << nPermutationsPerIteration << std::endl;
    std::cout << "Number of Passes = " << numIterations << std::endl;


    int i = 0;
    /* Permutation loop */
    #if OPENMP_ENABLED
        #pragma omp parallel for
    #endif
    for(i = 0;i < numIterations;i++)
    {
        start = nPermutationsPerIteration * i;
        end = (nPermutationsPerIteration * i) + nPermutationsPerIteration - 1;
        printf("Iteration %d , start %d, end %d of %d \n", i, start, end, nPermutations-1);

        g1Mean = (permutationMatrix1(arma::span(start,end), arma::span::all) * data) / nGroup1;
        g2Mean = (permutationMatrix2(arma::span(start,end), arma::span::all) * data) / nGroup2;
        g1Var = ((permutationMatrix1(arma::span(start,end), arma::span::all) * dataSquared) / (nGroup1)) - (g1Mean % g1Mean); 
        g2Var = ((permutationMatrix2(arma::span(start,end), arma::span::all) * dataSquared) / (nGroup2)) - (g2Mean % g2Mean); 

        tStatMatrix = (g1Mean - g2Mean) / (sqrt((g1Var/(nGroup1-1)) + (g2Var/(nGroup2-1))));
        maxT(arma::span(start,end),arma::span::all) = arma::max(tStatMatrix,1);
    }
    if(lastIteration != 0)
    {
        start = nPermutationsPerIteration * i;
        end = nPermutations - 1;
        printf("Iteration %d , start %d, end %d of %d \n", i, start, end, nPermutations-1);

        g1Mean = (permutationMatrix1(arma::span(start,end), arma::span::all) * data) / nGroup1;
        g2Mean = (permutationMatrix2(arma::span(start,end), arma::span::all) * data) / nGroup2;
        g1Var = ((permutationMatrix1(arma::span(start,end), arma::span::all) * dataSquared) / (nGroup1)) - (g1Mean % g1Mean); 
        g2Var = ((permutationMatrix2(arma::span(start,end), arma::span::all) * dataSquared) / (nGroup2)) - (g2Mean % g2Mean); 

        tStatMatrix = (g1Mean - g2Mean) / (sqrt((g1Var/(nGroup1-1)) + (g2Var/(nGroup2-1))));
        maxT(arma::span(start,end),arma::span::all) = arma::max(tStatMatrix,1);   
    }
    std::string prefix = "MaxT_CPU";
    SaveMaxT(maxT, nPermutations, prefix);

    return maxT;
}
Пример #5
0
arma::mat OneSamplePermTestingCPU(arma::mat data, 
                                  int nPermutations,
                                  double maxMemory)
{
    std::string permMatrixPath = "/Users/felipegb94/PermTest/data/face/PermutationMatrix.arma";
    int N; // Total number of subjects
    int V; // Total number of statistics/voxels to be tested
    int nPermutationsPerIteration; // Number of permutations done at once
    int numIterations; // nPermutations/nPermutationsPerIteration
    int lastIteration;
    int start, end; // Start and end of current interval

    arma::mat permutationMatrix;
    arma::mat maxT; // Maximum null distribution
    arma::mat dataSquared;
    arma::mat gMean;
    arma::mat gVar;
    arma::mat tStatMatrix;

    /* Set constant values and allocate memory */   
    N = data.n_rows; 
    V = data.n_cols;
    //permutationMatrix.load(permMatrixPath);
    permutationMatrix = OneSampleGetPermutationMatrix(nPermutations, N);
    dataSquared = data % data;
    nPermutationsPerIteration = GetIntervalDimension(V, maxMemory);
    lastIteration = nPermutations % nPermutationsPerIteration;
    numIterations = floor(nPermutations/nPermutationsPerIteration);
    maxT = arma::zeros(nPermutations,1);

    std::cout << "Number of subjects (rows in data matrix): " << N << std::endl;
    std::cout << "Number of voxels per subject (cols in data matrix and cols in indexMatrix): ";
    std::cout << V << std::endl;
    std::cout << "Number of Permutations (rows in permutations matrix):" << nPermutations << std::endl;
    std::cout << "Rows in permutationMatrix = " << permutationMatrix.n_rows << std::endl;
    std::cout << "Cols in permutationMatrix = " << permutationMatrix.n_cols << std::endl;
    std::cout << "Interval Size = " << nPermutationsPerIteration << std::endl;
    std::cout << "Number of Passes = " << numIterations << std::endl;
    std::cout << "Last Iteration = " << lastIteration << std::endl;

    int i = 0;

    arma::mat varTerm1 = repmat(arma::sum(dataSquared,0), nPermutationsPerIteration,1)/N;
    arma::mat varTerm1LastItr = repmat(arma::sum(dataSquared,0), lastIteration, 1)/N;
    std::cout << "VarTerm rows " << varTerm1LastItr.n_rows << std::endl;
    std::cout << "VarTerm cols " << varTerm1LastItr.n_cols << std::endl;
    /* Permutation loop */
    #if OPENMP_ENABLED
        #pragma omp parallel for
    #endif
    for(i = 0;i < numIterations;i++)
    {
        start = nPermutationsPerIteration * i;
        end = (nPermutationsPerIteration * i) + nPermutationsPerIteration - 1;
        printf("Iteration %d , start %d, end %d of %d \n", i, start, end, nPermutations-1);

        gMean = (permutationMatrix(arma::span(start,end), arma::span::all) * data) / N;
        gVar = (varTerm1) - (gMean % gMean); 
        tStatMatrix = (gMean) / sqrt(gVar/(N-1));

        maxT(arma::span(start,end),arma::span::all) = arma::max(tStatMatrix,1);
    }
    if(lastIteration != 0)
    {
        start = nPermutationsPerIteration * i;
        end = nPermutations - 1;
        printf("Iteration %d , start %d, end %d of %d \n", i, start, end, nPermutations-1);

        gMean = (permutationMatrix(arma::span(start,end), arma::span::all) * data) / N;
        gVar = varTerm1LastItr - (gMean % gMean); 
        tStatMatrix = (gMean) / sqrt(gVar/(N-1));

        maxT(arma::span(start,end),arma::span::all) = arma::max(tStatMatrix,1);
    }

    std::string prefix = "OneSampleMaxT_CPU";
    SaveMaxT(maxT, nPermutations, prefix);

    return maxT;
}
Пример #6
0
	bool accurateCollision(const VC3 &objectPosition, CollisionData &collisionData, const VC3 &rayOrigin_, const VC3 &rayDirection_)
	{
		bool inside = true;
		int i = 0;

		VC3 rayOrigin = rayOrigin_;
		VC3 rayDirection = rayDirection_;

		Vector minB = objectPosition - Vector(data.radiusX, 0, data.radiusZ);
		Vector maxB = objectPosition + Vector(data.radiusX, data.height, data.radiusZ);
		Vector maxT(-1, -1, -1);
		Vector collision;

		for(i = 0; i < 3; ++i)
		{
			//if(get(collisionData.rayOrigin, i) < get(minB, i))
			if(get(rayOrigin, i) < get(minB, i))
			{
				get(collision, i) = get(minB, i);
				inside = false;

				//if(getInteger(get(collisionData.rayDirection, i)))
				//	get(maxT, i) = (get(minB,i) - get(collisionData.rayOrigin, i)) / get(collisionData.rayDirection, i);
				if(getInteger(get(rayDirection, i)))
					get(maxT, i) = (get(minB,i) - get(rayOrigin, i)) / get(rayDirection, i);
			}
			//else if(get(collisionData.rayOrigin, i) > get(maxB, i))
			else if(get(rayOrigin, i) > get(maxB, i))
			{
				get(collision, i) = get(maxB, i);
				inside = false;

				//if(getInteger(get(collisionData.rayDirection, i)))
				//	get(maxT, i) = (get(maxB,i) - get(collisionData.rayOrigin, i)) / get(collisionData.rayDirection, i);
				if(getInteger(get(rayDirection, i)))
					get(maxT, i) = (get(maxB,i) - get(rayOrigin, i)) / get(rayDirection, i);
			}
		}

		if(inside)
			return true;

		int whichPlane = 0;
		if(get(maxT, 1) > get(maxT, whichPlane))
			whichPlane = 1;
		if(get(maxT, 2) > get(maxT, whichPlane))
			whichPlane = 2;

		if(getInteger(get(maxT, whichPlane)) & 0x80000000)
			return false;

		for(i = 0; i < 3; ++i)
		{
			if(i == whichPlane)
				continue;

			//get(collision, i) = get(collisionData.rayOrigin, i) + get(maxT, whichPlane) * get(collisionData.rayDirection, i);
			get(collision, i) = get(rayOrigin, i) + get(maxT, whichPlane) * get(rayDirection, i);
			if(get(collision, i) < get(minB, i) || get(collision, i) > get(maxB, i)) 
				return false;
		}

		return true;
	}
Пример #7
0
osg::Group *vpb::MyCompositeDestination::convertModel(osg::Group *group){
    if(!group)
        return NULL;
    //
    if(group->getNumChildren() == 0)
        return group;
    if(!std::isfinite(group->getBound().radius()) || group->getBound().radius() < 0.0)
        return group;
    //double l=group->getBound().radius();
    //printf("Brav %f\n",l);
    /* if(_level!=_numLevels)
        return group;
    writeCameraMatrix(group);
    return group;
*/
    if(!_useReImage)
        return group;
    osg::ref_ptr<osg::Image> image;


    osg::Matrix toScreen;
    osg::Vec2Array *texCoord=new osg::Vec2Array();
    osg::Geometry *newGeom = new osg::Geometry;
    // osg::Group *group= findTopMostNodeOfType<osg::Group>(model);
    osg::Vec3Array *newVerts= new osg::Vec3Array;
    osg::Vec4Array *newColors= new osg::Vec4Array;

    osg::DrawElementsUInt* newPrimitiveSet = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES,0);
    osg::Geode *newGeode=new osg::Geode;
    osg::Vec2 minT(DBL_MAX,DBL_MAX),maxT(-DBL_MAX,-DBL_MAX);
    // ("subtile.tif");

    int origX=dynamic_cast<MyDataSet*>(_dataSet)->in->Xsize(),origY=dynamic_cast<MyDataSet*>(_dataSet)->in->Ysize();
    osg::Matrix bottomLeftToTopLeft= (osg::Matrix::scale(1,-1,1)*osg::Matrix::translate(0,origY,0));

    osg::Matrix toTex=dynamic_cast<MyDataSet*>(_dataSet)->viewProj*( osg::Matrix::translate(1.0,1.0,1.0)*osg::Matrix::scale(0.5*origX,0.5*origY,0.5f))*bottomLeftToTopLeft;

    for(int i=0; i< (int)group->getNumChildren(); i++){

        osg::Group *group2  = dynamic_cast< osg::Group*>(group->getChild(i));
        osg::Geode *geode;
        if(group2)
            geode=group2->getChild(0)->asGeode();
        else
            geode = dynamic_cast< osg::Geode*>(group->getChild(i));

        osg::Drawable *drawable=geode->getDrawable(0);
        osg::Geometry *geom = dynamic_cast< osg::Geometry*>(drawable);
        osg::Vec3Array *verts=static_cast<const osg::Vec3Array*>(geom->getVertexArray());
        osg::Vec4Array *colors=static_cast<const osg::Vec4Array*>(geom->getColorArray());
        osg::DrawElementsUInt* primitiveSet = dynamic_cast<osg::DrawElementsUInt*>(geom->getPrimitiveSet(0));
        int offset=newVerts->size();
        if(!verts || !primitiveSet)
            continue;
        for(int j=0; j< (int)verts->size(); j++){
            osg::Vec4 pt(verts->at(j)[0],verts->at(j)[1],verts->at(j)[2],1.0);

            osg::Vec4 rotpt=pt*dynamic_cast<MyDataSet*>(_dataSet)->rotMat;

            osg::Vec4 proj=rotpt*toTex;
            proj.x() /= proj.w();
            proj.y() /= proj.w();
            //  std::cout << pt << " rot " <<pt*dynamic_cast<MyDataSet*>(_dataSet)->rotMat<<" proj "<< proj << "\n";

            for(int k=0; k <2; k++){
                if(proj[k]< minT[k])
                    minT[k]=proj[k];
                if(proj[k]> maxT[k])
                    maxT[k]=proj[k];
            }
            newVerts->push_back(verts->at(j));
            float height=verts->at(j)[2];
            osg::Vec4 zrange=dynamic_cast<MyDataSet*>(_dataSet)->_zrange;
            float range=zrange[1]-zrange[0];
            //printf("%f %f\n",zrange[0],height);
            float val =(height-zrange[0])/range;
            //printf("val %f\n",val);
            double ao=1.0;
            if(colors)
                ao=colors->at(j)[0];
            newColors->push_back(rainbowColorMap(val)*ao);

        }
        for(int j=0; j< (int)primitiveSet->getNumIndices(); j++){

            newPrimitiveSet->addElement(offset+primitiveSet->getElement(j));

        }

    }
    osg::Vec4 texSizes;
    osg::Vec4 ratio(0.0,0.0,0,0);

    if(0){
        ///OLD slow render
        texSizes=osg::Vec4(1024,1024,1024,1024);
        osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
        traits->x =0;
        traits->y = 0;
        traits->width = 1024;
        traits->height = 1024;
        traits->windowDecoration = false;
        traits->doubleBuffer = false;
        traits->sharedContext = 0;
        traits->pbuffer = true;

        osg::ref_ptr<osg::GraphicsContext> _gc= osg::GraphicsContext::createGraphicsContext(traits.get());

        if (!_gc)
        {
            osg::notify(osg::NOTICE)<<"Failed to create pbuffer, failing back to normal graphics window."<<std::endl;

            traits->pbuffer = false;
            _gc = osg::GraphicsContext::createGraphicsContext(traits.get());
        }


        //printf("%d\n",newVerts->size());
        render(group,image,*_gc,toScreen,texSizes);
    }else{
        //std::cout << minV << " "<<maxV<<std::endl;
        //int start_pow=9;
        //tex_size=1024;//log2 = 10
        int leveloffset=(_numLevels-_level);
        leveloffset=std::min(leveloffset,5);

        toScreen=dynamic_cast<MyDataSet*>(_dataSet)->getImageSection(*(dynamic_cast<MyDataSet*>(_dataSet)->in),minT,maxT,origX,origY,texSizes, toTex,image,ratio,leveloffset);
    }

    for(int j=0; j< (int)newVerts->size(); j++){

        texCoord->push_back(calcCoordReprojTrans(newVerts->at(j),dynamic_cast<MyDataSet*>(_dataSet)->rotMat,toScreen,osg::Vec2(texSizes[2],texSizes[3]),ratio));
        //  std::cout <<texCoord->back() << std::endl;

    }
    for(int j=0; j< (int)newPrimitiveSet->getNumIndices(); j++){
        if(newPrimitiveSet->getElement(j) < 0 || newPrimitiveSet->getElement(j) > newVerts->size() ){
            printf("ASDADASDASDASDADS\n");
            exit(-1);
        }
    }
    //printf("%d %d\n",newPrimitiveSet->getNumIndices(),        newPrimitiveSet->getNumIndices()/3);


    newGeom->setTexCoordArray(0,texCoord);
    newGeom->setVertexArray(newVerts);
    newGeom->setColorArray(newColors);
    newGeom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);

    newGeom->addPrimitiveSet(newPrimitiveSet);
    newGeom->setUseDisplayList(_useDisplayLists);
    newGeom->setUseVertexBufferObjects(_useVBO);

    newGeode->addDrawable(newGeom);
    char tmp[128];
    // if(image->s() != image->t()){
    sprintf(tmp,"%d-%d-%d.png",image->s(),image->t(),rand());
    // osgDB::writeImageFile(*image.get(),tmp);
    //}
    osg::ref_ptr<osg::Texture2D> texture=new osg::Texture2D(image);
    texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_BORDER);
    texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_BORDER);
    texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR_MIPMAP_LINEAR);
    texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
    texture->setTextureSize(image->s(),image->t());
    //std::cout <<  "Check it "<<texture->getTextureWidth() << " "<< texture->getTextureHeight()<<"\n";

    osg::Texture::InternalFormatMode internalFormatMode = osg::Texture::USE_IMAGE_DATA_FORMAT;
    internalFormatMode = osg::Texture::USE_S3TC_DXT1_COMPRESSION;
    /*  switch(getImageOptions(layerNum)->getTextureType())
    {
    case(BuildOptions::RGB_S3TC_DXT1): internalFormatMode = osg::Texture::USE_S3TC_DXT1_COMPRESSION; break;
    case(BuildOptions::RGBA_S3TC_DXT1): internalFormatMode = osg::Texture::USE_S3TC_DXT1_COMPRESSION; break;
    case(BuildOptions::RGBA_S3TC_DXT3): internalFormatMode = osg::Texture::USE_S3TC_DXT3_COMPRESSION; break;
    case(BuildOptions::RGBA_S3TC_DXT5): internalFormatMode = osg::Texture::USE_S3TC_DXT5_COMPRESSION; break;
    case(BuildOptions::ARB_COMPRESSED): internalFormatMode = osg::Texture::USE_ARB_COMPRESSION; break;
    case(BuildOptions::COMPRESSED_TEXTURE): internalFormatMode = osg::Texture::USE_S3TC_DXT1_COMPRESSION; break;
    case(BuildOptions::COMPRESSED_RGBA_TEXTURE): internalFormatMode = osg::Texture::USE_S3TC_DXT3_COMPRESSION; break;
    default: break;
    }
*/
    bool compressedImageRequired = (internalFormatMode != osg::Texture::USE_IMAGE_DATA_FORMAT);
    //  image->s()>=minumCompressedTextureSize && image->t()>=minumCompressedTextureSize &&

    if (1 &&/*compressedImageSupported && */compressedImageRequired )
    {
        log(osg::NOTICE,"Compressed image");


            OpenThreads::ScopedLock<OpenThreads::Mutex> lock(dynamic_cast<MyDataSet*>(_dataSet)->_imageMutex);
            compress(*_dataSet->getState(),*texture,internalFormatMode,generateMiMap,resizePowerOfTwo);
       // }
      //  vpb::generateMipMap(*_dataSet->getState(),*texture,resizePowerOfTwo,vpb::BuildOptions::GL_DRIVER);

     //   log(osg::INFO,">>>>>>>>>>>>>>>compressed image.<<<<<<<<<<<<<<");

    }

    osg::StateSet *stateset=newGeode->getOrCreateStateSet();

    stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
    // stateset->setMode( GL_LIGHTING, osg::StateAttribute::PROTECTED | osg::StateAttribute::OFF );
    osg::TexEnvCombine *te = new osg::TexEnvCombine;
    // Modulate diffuse texture with vertex color.
    te->setCombine_RGB(osg::TexEnvCombine::REPLACE);
    te->setSource0_RGB(osg::TexEnvCombine::TEXTURE);
    te->setOperand0_RGB(osg::TexEnvCombine::SRC_COLOR);
    te->setSource1_RGB(osg::TexEnvCombine::PREVIOUS);
    te->setOperand1_RGB(osg::TexEnvCombine::SRC_COLOR);

    // Alpha doesn't matter.
    te->setCombine_Alpha(osg::TexEnvCombine::REPLACE);
    te->setSource0_Alpha(osg::TexEnvCombine::PREVIOUS);
    te->setOperand0_Alpha(osg::TexEnvCombine::SRC_ALPHA);

    stateset->setTextureAttribute(0, te);

    stateset->setDataVariance(osg::Object::STATIC);
    //   osgUtil::ShaderGenVisitor sgv;
    // newGeode->accept(sgv);

    // osg::Vec3 v(1972.38,3932.55,0);
    //osg::Vec3 v(302.3,334.3,0);
    //  std::cout << v*toScreen << " " << toScreen<<std::endl;
    // osgDB::Registry::instance()->writeImage( *image,"ass.png",NULL);
    osg::Group *newGroup=new osg::Group;
    newGroup->addChild(newGeode);
    osgUtil::SmoothingVisitor sv;
    newGroup->accept(sv);

    return newGroup;

}