예제 #1
0
int	pyramid(int size, int **map, int current, int pos)
{
  if (current == size - 1)
    {
      return MIN(map[current][pos], map[current][pos + 1]);
    }
  return MIN(pyramid(size, map, current + 1, pos), pyramid(size, map, current + 1, pos + 1)) + map[current][pos];
}
예제 #2
0
int OrientationSaliencyMap::calculatePyramidSimple()
{
  calculated = false;

  int rt_code = checkParameters();
  if(rt_code != AM_OK)
    return(rt_code);
  
  printf("[INFO]: %s: Computation Simple pyramid started.\n",mapName.c_str());
  
  SimplePyramid::Ptr pyramid( new SimplePyramid() );
  
  pyramid->setStartLevel(0);
  pyramid->setMaxLevel(6);
  pyramid->setSMLevel(0);
  pyramid->setWidth(width);
  pyramid->setHeight(height);
  pyramid->setNormalizationType(normalization_type);
  
  cv::Mat image_cur;
  image.copyTo(image_cur);
  image_cur.convertTo(image_cur,CV_32F,1.0f/255);
  cv::Mat image_gray;
  cv::cvtColor(image_cur,image_gray,CV_BGR2GRAY);
  
  pyramid->setImage(image_gray);
  pyramid->buildPyramid();
  pyramid->print();

  combinePyramid(pyramid);
  
  calculated = true;
  printf("[INFO]: %s: Pyramid computation succeed.\n",mapName.c_str());
  return(AM_OK);
}
예제 #3
0
int main(){

	std::cout << "hello world"<<std::endl;

/*
	PASCAL pascal;
	pascal.add_row(4);
	pascal.print();

	pascal.add_row(10);
	pascal.print();
*/
//	std::cout << pascal.get_n_digits(1) <<std::endl;
//	std::cout << pascal.get_n_digits(5) <<std::endl;
//	std::cout << pascal.get_n_digits(50) <<std::endl;
//	std::cout << pascal.get_n_digits(10000001) <<std::endl;

	PYRAMID pyramid(10);
	pyramid.create();
	pyramid.print();
	
	//std::cout << p.get() << std::endl;
/*
	PLAQUE_COLLECTION plaques;
	plaques.add_plaque(PLAQUE("WQ"));
	plaques.add_plaque(PLAQUE("WQq"));
	plaques.print();
*/
	return 0;
}
예제 #4
0
// HighContrastOp Method Definitions
void HighContrastOp::Map(const float *y, int xRes, int yRes,
		float maxDisplayY, float *scale) const {
	// Find minimum and maximum image luminances
	float minY = y[0], maxY = y[0];
	for (int i = 0; i < xRes * yRes; ++i) {
		minY = min(minY, y[i]);
		maxY = max(maxY, y[i]);
	}
	float CYmin = C(minY), CYmax = C(maxY);
	// Build luminance image pyramid
	MIPMap<float> pyramid(xRes, yRes,
	                      y, false,
						  4.f, TEXTURE_CLAMP);
	// Apply high contrast tone mapping operator
	ProgressReporter progress(xRes*yRes, "Tone Mapping"); // NOBOOK
	for (int y = 0; y < yRes; ++y) {
		float yc = (float(y) + .5f) / float(yRes);
		for (int x = 0; x < xRes; ++x) {
			float xc = (float(x) + .5f) / float(xRes);
			// Compute local adaptation luminance at $(x,y)$
			float dwidth = 1.f / float(max(xRes, yRes));
			float maxWidth = 32.f / float(max(xRes, yRes));
			float width = dwidth, prevWidth = 0.f;
			float Yadapt;
			float prevlc = 0.f;
			const float maxLocalContrast = .5f;
			while (1) {
				// Compute local contrast at $(x,y)$
				float b0 = pyramid.Lookup(xc, yc, width,
				                          0.f, 0.f, width);
				float b1 = pyramid.Lookup(xc, yc, 2.f*width,
				                          0.f, 0.f, 2.f*width);
				float lc = fabsf((b0 - b1) / b0);
				// If maximum contrast is exceeded, compute adaptation luminance
				if (lc > maxLocalContrast) {
					float t = (maxLocalContrast - prevlc) / (lc - prevlc);
					float w = Lerp(t, prevWidth, width);
					Yadapt = pyramid.Lookup(xc, yc, w,
					                        0.f, 0.f, w);
					break;
				}
				// Increase search region and prepare to compute contrast again
				prevlc = lc;
				prevWidth = width;
				width += dwidth;
				if (width >= maxWidth) {
					Yadapt = pyramid.Lookup(xc, yc, maxWidth,
					                        0.f, 0.f, maxWidth);
					break;
				}
			}
			// Apply tone mapping based on local adaptation luminance
			scale[x + y*xRes] = T(Yadapt, CYmin, CYmax, maxDisplayY) /
				Yadapt;
		}
		progress.Update(xRes); // NOBOOK
	}
	progress.Done(); // NOBOOK
}
예제 #5
0
void PyramidTest::testGetPips() {
    unsigned int colour = 3;
    unsigned int pips = 1;
    Pyramid pyramid(colour, pips);

    unsigned int result = pyramid.getPips();
    CPPUNIT_ASSERT(result == pips);
}
예제 #6
0
static void renderScene1()
{
    for(int x=-10; x<=10; x++)
        for(int y=-10;y<=10; y++)
        {
            if( (x+y) % 2 == 0) continue;
            for(int i = -100; i<=100;i++)
            {
                pyramid(Point3f(x,i,y), 0.4);
            }
        }
}
예제 #7
0
int main(void)
{    
    int n;
    int repeat, ri;
    void pyramid(int n);

    scanf("%d", &repeat);
    for(ri = 1; ri <= repeat; ri++){
        scanf("%d", &n);
        pyramid(n);
    }
}
예제 #8
0
int CFFLD::detector( Mat img, string strModelFile, float threshold, vector<DetectionResult> & result )
{
	// For xml model;
    CvLSVMFilterObject** filters = 0;
    int kFilters = 0;
    int kComponents = 0;
    int* kPartFilters = 0;
    float* b = 0;
    float scoreThreshold = 0.f;
    int err_code = 0;

    Object::Name name = Object::PERSON;
	string results;
	string images(".");
    int nbNegativeScenes = -1;
	int padding = 12;
	int interval = 10;
	//double threshold =-0.50;
	double overlap = 0.5;

	// load xml file
    err_code = loadModel( strModelFile.c_str(), &filters, &kFilters, &kComponents, &kPartFilters, &b, &scoreThreshold );

    if( err_code != 0 )
    {
    	cout<<"Invalid xml model file."<<endl;
    	return 0;
    }

 	Mixture mixture;
 	mixture.importFromOpenCVModel( kFilters, kComponents, kPartFilters, b, filters );

	JPEGImage image( img );
	HOGPyramid pyramid(image, padding, padding, interval);

	// Initialize the Patchwork class
	if ( !Patchwork::Init((pyramid.levels()[0].rows() - padding + 15) & ~15,
						  (pyramid.levels()[0].cols() - padding + 15) & ~15) ) 
	{
		cerr << "\nCould not initialize the Patchwork class" << endl;
		return -1;
	}

	mixture.cacheFilters();
	
	// Compute the detections
	vector<Detection> detections;
	ofstream out;
	string file;
	detect(mixture, image.width(), image.height(), pyramid, threshold, overlap, file, out,
		   images, detections, result );
}
void
init( void )
{
    // Create the point and color arrays
    point4 *points = new point4[numPoints];
    color4 *colors = new color4[numPoints];

    // Set up the ovoid globe
    globe( longDivs, latDivs, points, 0 );
    globeColors( longDivs, latDivs, colors, 0 );

    // Set up the pyramid
    pyramid( pyrBaseVerts, points, pyrStart );
    randomColors( numPyrPoints, colors, pyrStart );

    // Create a vertex array object
    GLuint vao;
    glGenVertexArrays( 1, &vao );
    glBindVertexArray( vao );

    // Create and initialize a buffer object
    GLuint buffer;
    glGenBuffers( 1, &buffer );
    glBindBuffer( GL_ARRAY_BUFFER, buffer );
    glBufferData( GL_ARRAY_BUFFER, numPoints * (sizeof(point4) + sizeof(color4)),
                  NULL, GL_STATIC_DRAW );
    glBufferSubData( GL_ARRAY_BUFFER, 0, numPoints * sizeof(point4), points );
    glBufferSubData( GL_ARRAY_BUFFER, numPoints * sizeof(point4),
                     numPoints * sizeof(color4), colors );

    // Load shaders and use the resulting shader program
    GLuint program = InitShader( "movingGlobe_vs.glsl", "movingGlobe_fs.glsl" );
    glUseProgram( program );

    // Initialize the vertex position attribute from the vertex shader
    GLuint vPosition = glGetAttribLocation( program, "vPosition" );
    glEnableVertexAttribArray( vPosition );
    glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0,
                           BUFFER_OFFSET(0) );

    GLuint vColor = glGetAttribLocation( program, "vColor" );
    glEnableVertexAttribArray( vColor );
    glVertexAttribPointer( vColor, 4, GL_FLOAT, GL_FALSE, 0,
                           BUFFER_OFFSET(numPoints * sizeof(point4)) );

    model_view = glGetUniformLocation( program, "model_view" );
    projection = glGetUniformLocation( program, "projection" );

    glEnable( GL_DEPTH_TEST ); 
    glClearColor( 1.0, 0.9, 0.75, 1.0 ); // light yellow background
}
예제 #10
0
QSet<TileId> PlacemarkLayout::visibleTiles( const ViewportParams *viewport )
{
    int zoomLevel = qLn( viewport->radius() *4 / 256 ) / qLn( 2.0 );

    /*
     * rely on m_placemarkCache to find the placemarks for the tiles which
     * matter. The top level tiles have the more popular placemarks,
     * the bottom level tiles have the smaller ones, and we only get the ones
     * matching our latLonAltBox.
     */

    qreal north, south, east, west;
    viewport->viewLatLonAltBox().boundaries(north, south, east, west);
    QSet<TileId> tileIdSet;
    QVector<QRectF> geoRects;
    if( west <= east ) {
        geoRects << QRectF(west, north, east - west, south - north);
    } else {
        geoRects << QRectF(west, north, M_PI - west, south - north);
        geoRects << QRectF(-M_PI, north, east + M_PI, south - north);
    }
    foreach( const QRectF &geoRect, geoRects ) {
        TileId key;
        QRect rect;

        key = TileId::fromCoordinates( GeoDataCoordinates(geoRect.left(), north, 0), zoomLevel);
        rect.setLeft( key.x() );
        rect.setTop( key.y() );

        key = TileId::fromCoordinates( GeoDataCoordinates(geoRect.right(), south, 0), zoomLevel);
        rect.setRight( key.x() );
        rect.setBottom( key.y() );

        TileCoordsPyramid pyramid(0, zoomLevel );
        pyramid.setBottomLevelCoords( rect );

        for ( int level = pyramid.topLevel(); level <= pyramid.bottomLevel(); ++level ) {
        QRect const coords = pyramid.coords( level );
        int x1, y1, x2, y2;
        coords.getCoords( &x1, &y1, &x2, &y2 );
            for ( int x = x1; x <= x2; ++x ) {
                for ( int y = y1; y <= y2; ++y ) {
                    TileId const tileId( 0, level, x, y );
                    tileIdSet.insert(tileId);
                }
            }
        }
    }
예제 #11
0
QList< GeoGraphicsItem* > GeoGraphicsScene::items( const Marble::GeoDataLatLonAltBox& box, int maxZoomLevel ) const
{
    QList< GeoGraphicsItem* > result;
    QRect rect;
    qreal north, south, east, west;
    box.boundaries( north, south, east, west );
    TileId key;
    int zoomLevel = maxZoomLevel < s_tileZoomLevel ? maxZoomLevel : s_tileZoomLevel;

    key = d->coordToTileId( GeoDataCoordinates(west, north, 0), zoomLevel );
    rect.setLeft( key.x() );
    rect.setTop( key.y() );

    key = d->coordToTileId( GeoDataCoordinates(east, south, 0), zoomLevel );
    rect.setRight( key.x() );
    rect.setBottom( key.y() );
    
    TileCoordsPyramid pyramid( 0, zoomLevel );
    pyramid.setBottomLevelCoords( rect );

    for ( int level = pyramid.topLevel(); level <= pyramid.bottomLevel(); ++level ) {
        QRect const coords = pyramid.coords( level );
        int x1, y1, x2, y2;
        coords.getCoords( &x1, &y1, &x2, &y2 );
        for ( int x = x1; x <= x2; ++x ) {
            for ( int y = y1; y <= y2; ++y ) {
                TileId const tileId( "", level, x, y );
                const QList< GeoGraphicsItem* > &objects = d->m_items.value(tileId);
                QList< GeoGraphicsItem* >::iterator before = result.begin();
                QList< GeoGraphicsItem* >::const_iterator currentItem = objects.constBegin();
                while( currentItem != objects.end() )
                {  
                    while( ( currentItem != objects.end() )
                      && ( ( before == result.end() ) || ( (*currentItem)->zValue() < (*before)->zValue() ) ) )
                    {
                        if( (*currentItem)->minZoomLevel() <= maxZoomLevel )
                            before = result.insert( before, *currentItem );
                        currentItem++;
                    }
                    if ( before != result.end() )
                        before++;
                }
            }
        }
    }
    return result;
}
예제 #12
0
	//--------------------------------------------------
	// As of writing this, you can use:
	// ONEWAY, FERN, BruteForce, BruteForce-L1, Planar
	void MatchableImage::trainMatcher(string alg_name)
	{
		if(matcherTrained && matchAlgUsed.compare(alg_name)==0) return;
		
		log(LOG_LEVEL_DEBUG, "Training matcher %s", alg_name.c_str());
		
		/*
		// These don't require descriptors.  It's all rolled up in the matcher.
		if(!alg_name.compare("FERN")||!alg_name.compare("ONEWAY")||!alg_name.compare("CALONDER"))
		{
			findFeatures();
			genericDescriptorMatch = createDescriptorMatcher(alg_name, "fern_params.xml");
			
			log(LOG_LEVEL_DEBUG, "training matcher");
			Mat img = bw();
			genericDescriptorMatch->add( img, features );
			
		}
		*/
		
		if(!alg_name.compare("BruteForce")||!alg_name.compare("BruteForce-L1"))
		{
			findDescriptors();
			descriptorMatcher = createDescriptorMatcher(alg_name.c_str());
			descriptorMatcher->clear();
			descriptorMatcher->add( descriptors ); 
		}
		
		if(!alg_name.compare("Planar"))
		{
			if(featureAlgUsed.compare("L")!=0)
			{
				log(LOG_LEVEL_DEBUG, "Planar detector works best with L detector.  Switching!");
				findFeatures("L");
			}
			
			Size patchSize(32, 32);
			planarDetector.setVerbose(true);
			planarDetector.train(pyramid(ldetector.nOctaves-1), features, patchSize.width, 100, 11, 10000, ldetector, gen);
			
		}
		matchAlgUsed = alg_name;
	}
예제 #13
0
static void drawRecursivePyramid(Point3f top, float height)
{
    if(height <= 1){
        pyramid(top, height);
        rpyramid(Point3f(top.x,-top.y,top.z), height);
        return;
    }

    Point3f base1 = Point3f(top.x-height/2, top.y-height/2, top.z-height/2);
    Point3f base2 = Point3f(top.x-height/2, top.y-height/2, top.z+height/2);
    Point3f base3 = Point3f(top.x+height/2, top.y-height/2, top.z+height/2);
    Point3f base4 = Point3f(top.x+height/2, top.y-height/2, top.z-height/2);

    drawRecursivePyramid(top, height / 2);
    drawRecursivePyramid(base1, height / 2);
    drawRecursivePyramid(base2, height / 2);
    drawRecursivePyramid(base3, height / 2);
    drawRecursivePyramid(base4, height / 2);

}
예제 #14
0
int OrientationSaliencyMap::calculatePyramidItti()
{
  calculated = false;

  int rt_code = checkParameters();
  if(rt_code != AM_OK)
    return(rt_code);
  
  printf("[INFO]: %s: Computation Itti pyramid started.\n",mapName.c_str());
  
  IttiPyramid::Ptr pyramid( new IttiPyramid() );
  
  pyramid->setSMLevel(0);
  pyramid->setWidth(width);
  pyramid->setHeight(height);
  pyramid->setNormalizationType(normalization_type);
  
  pyramid->setLowestC(2);
  pyramid->setHighestC(4);
  pyramid->setSmallestCS(3);
  pyramid->setLargestCS(4);
  
  pyramid->setChangeSign(false);
  
  cv::Mat image_cur;
  image.copyTo(image_cur);
  image_cur.convertTo(image_cur,CV_32F,1.0f/255);
  cv::Mat image_gray;
  cv::cvtColor(image_cur,image_gray,CV_BGR2GRAY);
  
  pyramid->setImage(image_gray);
  pyramid->buildPyramid();
  pyramid->print();

  combinePyramid(pyramid);
  
  calculated = true;
  printf("[INFO]: %s: Pyramid computation succeed.\n",mapName.c_str());
  return(AM_OK);
}
예제 #15
0
    void MergeGroup::addImage(view_type const& image)
    {
        if (image.width() != width_ || image.height() != height_)
        {
            throw std::invalid_argument("Dimensions of image passed in differ to others in the sequence.");
        }

        if (pyramids_.size() == groupSize_)
        {
            throw std::invalid_argument("Group already contains enough images to fuse. Cannot add another.");
        }

        // TODO: do quality mask here, then create pyramid from Pending image

        // which image in the group is this
        size_t imageNum = pyramids_.size();

        // create subviews from arena for a single pyramid
        std::vector< view_type > subviews;
        for (auto& fuseView : fuseViews_)
        {
            subviews.push_back(fuseView[imageNum]);
        }

        // transfer input image into first level of pyramid
        std::copy(image.begin(), image.end(), subviews.front().begin());

        std::cout << "========================\n"
                     "Creating Pyramid.\n"
                     "========================"
                  << std::endl;
        ImagePyramid pyramid(context_, std::move(subviews),
                [=](Pending2DImage const& im)
                {
                    return createPyramidLevel(im, program_);
                });

        pyramids_.push_back(std::move(pyramid));
    }
예제 #16
0
// position is (x, y, z), d=dimension of base, h=height,
// e = "pointienss", c = color
static void drawObilisk(float x, float y, float z,
	float d, float h, float e, unsigned char c[])
{
	cube(x, y, z ,d, h, d, c);
	pyramid(x, y+h, z, d, h/e, d, c);
}
예제 #17
0
int	pyramid_path(int size, int **map)
{
  return pyramid(size, map, 0, 0);
}
예제 #18
0
// setter
int define::update(string& data) {
	const char* header = getHeader().c_str();
	
	// get the text
	vector<string> lines = BZWParser::getSectionsByHeader(header, data.c_str(), "enddef");
	
	if(lines[0] == BZW_NOT_FOUND)
		return 0;
	
	if(lines.size() > 1) {
		printf("define::update(): Error! Defined \"define\" %d times!\n", (int)lines.size());
		return 0;	
	}
	
	// get the name
	vector<string> names = BZWParser::getValuesByKey("define", header, lines[0].c_str());
	if(!hasOnlyOne(names, header))
		return 0;
			
	// get the data
	string::size_type sectionStart = lines[0].find("\n") + 1;
	string::size_type sectionLength = lines[0].find( "enddef", sectionStart ) - sectionStart;
	
	lines[0] = lines[0].substr( sectionStart, sectionLength );
	
	const char* defineData = lines[0].c_str();
	
	// get the chunks
	vector<string> chunks = BZWParser::getSections( defineData );
	
	// get all the supported objects from the lines, but don't commit them yet
	
	// arc
	vector<string> arcs = BZWParser::findSections("arc", chunks);
	vector<arc> arcData;
	if(arcs[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = arcs.begin(); i != arcs.end(); i++) {
			arc tmp = arc();
			if(!tmp.update(*i))
				return 0;
			arcData.push_back( tmp );	
		}	
	}
	
	// base
	vector<string> bases = BZWParser::findSections("base", chunks);
	vector<base> baseData;
	if(bases[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = bases.begin(); i != bases.end(); i++) {
			base tmp = base();
			if(!tmp.update(*i))
				return 0;
			baseData.push_back( tmp );	
		}	
	}
	
	// box
	vector<string> boxes = BZWParser::findSections("box", chunks);
	vector<box> boxData;
	if(boxes[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = boxes.begin(); i != boxes.end(); i++) {
			box tmp = box();
			if(!tmp.update(*i))
				return 0;
			boxData.push_back( tmp );	
		}	
	}
	
	// cone
	vector<string> cones = BZWParser::findSections("cone", chunks);
	vector<cone> coneData;
	if(cones[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = cones.begin(); i != cones.end(); i++) {
			cone tmp = cone();
			if(!tmp.update(*i))
				return 0;
			coneData.push_back( tmp );	
		}	
	}
	
	// group
	vector<string> groups = BZWParser::findSections("group", chunks);
	vector<group> groupData;
	if(groups[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = groups.begin(); i != groups.end(); i++) {
			group tmp = group();
			if(!tmp.update(*i))
				return 0;
			groupData.push_back( tmp );	
		}	
	}
	
	// mesh
	vector<string> meshes = BZWParser::findSections("mesh", chunks);
	vector<mesh> meshData;
	if(meshes[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = meshes.begin(); i != meshes.end(); i++) {
			mesh tmp = mesh();
			if(!tmp.update(*i))
				return 0;
			meshData.push_back( tmp );	
		}	
	}
	
	// meshbox
	vector<string> meshboxes = BZWParser::findSections("meshbox", chunks);
	vector<meshbox> meshboxData;
	if(meshboxes[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = meshboxes.begin(); i != meshboxes.end(); i++) {
			meshbox tmp = meshbox();
			if(!tmp.update(*i))
				return 0;
			meshboxData.push_back( tmp );	
		}	
	}
	
	// meshpyr
	vector<string> meshpyrs = BZWParser::findSections("meshpyr", chunks);
	vector<meshpyr> meshpyrData;
	if(meshpyrs[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = meshpyrs.begin(); i != meshpyrs.end(); i++) {
			meshpyr tmp = meshpyr();
			if(!tmp.update(*i))
				return 0;
			meshpyrData.push_back( tmp );	
		}	
	}
	
	// pyramid
	vector<string> pyramids = BZWParser::findSections("pyramid", chunks);
	vector<pyramid> pyramidData;
	if(pyramids[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = pyramids.begin(); i != pyramids.end(); i++) {
			pyramid tmp = pyramid();
			if(!tmp.update(*i))
				return 0;
			pyramidData.push_back( tmp );	
		}	
	}
	
	// sphere
	vector<string> spheres = BZWParser::findSections("sphere", chunks);
	vector<sphere> sphereData;
	if(spheres[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = spheres.begin(); i != spheres.end(); i++) {
			sphere tmp = sphere();
			if(!tmp.update(*i))
				return 0;
			sphereData.push_back( tmp );	
		}	
	}
	
	// teleporter
	vector<string> teleporters = BZWParser::findSections("teleporter", chunks);
	vector<teleporter> teleporterData;
	if(teleporters[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = teleporters.begin(); i != teleporters.end(); i++) {
			teleporter tmp = teleporter();
			if(!tmp.update(*i))
				return 0;
			teleporterData.push_back( tmp );	
		}	
	}
	
	// tetra
	vector<string> tetras = BZWParser::findSections("tetra", chunks);
	vector<tetra> tetraData;
	if(tetras[0] != BZW_NOT_FOUND) {
		for(vector<string>::iterator i = tetras.begin(); i != tetras.end(); i++) {
			tetra tmp = tetra();
			if(!tmp.update(*i))
				return 0;
			tetraData.push_back( tmp );	
		}	
	}
	
	
	// base-class update (must be done BEFORE commiting new objects)
	if(!DataEntry::update(data)) {
		return 0;
	}
	
	// commit name
	name = names[0];
	
	// free previous objects	
	objects.clear();
	
	// commit arcs
	if(arcData.size() > 0) {
		for(vector<arc>::iterator i = arcData.begin(); i != arcData.end(); i++) {
			objects.push_back( new arc(*i) );	
		}	
	}
	
	// commit bases
	if(baseData.size() > 0) {
		for(vector<base>::iterator i = baseData.begin(); i != baseData.end(); i++) {
			objects.push_back( new base(*i) );	
		}	
	}
	
	// commit boxes
	if(boxData.size() > 0) {
		for(vector<box>::iterator i = boxData.begin(); i != boxData.end(); i++) {
			objects.push_back( new box(*i) );	
		}	
	}
	
	// commit cones
	if(coneData.size() > 0) {
		for(vector<cone>::iterator i = coneData.begin(); i != coneData.end(); i++) {
			objects.push_back( new cone(*i) );	
		}	
	}
	
	// commit groups
	if(groupData.size() > 0) {
		for(vector<group>::iterator i = groupData.begin(); i != groupData.end(); i++) {
			objects.push_back( new group(*i) );	
		}	
	}
	
	// commit meshes
	if(meshData.size() > 0) {
		for(vector<mesh>::iterator i = meshData.begin(); i != meshData.end(); i++) {
			objects.push_back( new mesh(*i) );	
		}	
	}
	
	// commit meshboxes
	if(meshboxData.size() > 0) {
		for(vector<meshbox>::iterator i = meshboxData.begin(); i != meshboxData.end(); i++) {
			objects.push_back( new meshbox(*i) );	
		}	
	}
	
	// commit meshpyrs
	if(meshpyrData.size() > 0) {
		for(vector<meshpyr>::iterator i = meshpyrData.begin(); i != meshpyrData.end(); i++) {
			objects.push_back( new meshpyr(*i) );	
		}	
	}
	
	// commit pyramids
	if(pyramidData.size() > 0) {
		for(vector<pyramid>::iterator i = pyramidData.begin(); i != pyramidData.end(); i++) {
			objects.push_back( new pyramid(*i) );	
		}	
	}
	
	// commit spheres
	if(sphereData.size() > 0) {
		for(vector<sphere>::iterator i = sphereData.begin(); i != sphereData.end(); i++) {
			objects.push_back( new sphere(*i) );	
		}	
	}
	
	// commit teleporters
	if(teleporterData.size() > 0) {
		for(vector<teleporter>::iterator i = teleporterData.begin(); i != teleporterData.end(); i++) {
			objects.push_back( new teleporter(*i) );	
		}
	}
	
	// commit tetras
	if(tetraData.size() > 0) {
		for(vector<tetra>::iterator i = tetraData.begin(); i != tetraData.end(); i++) {
			objects.push_back( new tetra(*i) );	
		}	
	}
	
	return 1;
}
예제 #19
0
int					regFloat3d		(struct	rParam		*regDataPtr) {

    struct	fitRec		fit, invFit;
    float				*pyrHdl1[maxPyrLevels], *pyrHdl2[maxPyrLevels];
    float				*mskHdl1[maxPyrLevels], *mskHdl2[maxPyrLevels];
    float				*inPtr1, *inPtr2;
    float				*outPtr;
    float				*mskPtr1, *mskPtr2;
    float				*mskPtr;
    float				*u;
    double				origin[3];
    double				epsilon[maxPyrLevels];
    long				nxRange[maxPyrLevels];
    long				nyRange[maxPyrLevels];
    long				nzRange[maxPyrLevels];
    int					ia[hessianSize];
    double				mse, snr;
    double				lambda;
    double				x1, y1, z1;
    double				x2, y2, z2;
    double				mean;
    int					nx, ny, nz;
    int					k, l;
    int					x, y, z;

    switch (regDataPtr->directives.convergence) {
    case gravity:
        if (regDataPtr->directives.isoScaling || regDataPtr->directives.xRot
                || regDataPtr->directives.yRot || regDataPtr->directives.zRot
                || regDataPtr->directives.xSkew || regDataPtr->directives.ySkew
                || regDataPtr->directives.zSkew || regDataPtr->directives.matchGrey) {
            message("ERROR - Gravity center can only be translated");
            return(ERROR);
        }
        else if ((regDataPtr->directives.importFit != 0) && (regDataPtr->directives.xTrans
                 || regDataPtr->directives.yTrans || regDataPtr->directives.zTrans))
            message("WARNING - Ignoring 'importFit' parameter");
        break;
    case Marquardt:
        break;
    default:
        message("ERROR - Unknown convergence specification");
        return(ERROR);
    }
    switch (regDataPtr->directives.interpolation) {
    case zero:
        if (regDataPtr->directives.convergence != gravity) {
            message("ERROR - Nearest neighbor interpolation valid only for gravity");
            return(ERROR);
        }
    case one:
    case three:
        break;
    default:
        message("ERROR - Unknown interpolation specification");
        return(ERROR);
    }
    if (regDataPtr->directives.zSqueeze && (regDataPtr->nz == 1)) {
        message("ERROR - Inconsistent parameters: unable to shrink Z-axis in 2-D");
        return(ERROR);
    }
    if ((!regDataPtr->directives.zSqueeze) && (regDataPtr->nz != 1)
            && regDataPtr->directives.isoScaling) {
        message("ERROR - Inconsistent parameters: zSqueeze needed for isoScaling in 3-D");
        return(ERROR);
    }
    if (regDataPtr->directives.isoScaling && (regDataPtr->directives.xSkew
            || regDataPtr->directives.ySkew || regDataPtr->directives.zSkew)) {
        message("ERROR - Inconsistent parameters: (x,y,z)Skew and isoScaling");
        return(ERROR);
    }
    if ((regDataPtr->directives.xRot || regDataPtr->directives.yRot
            || regDataPtr->directives.zRot) && (regDataPtr->directives.xSkew
                    || regDataPtr->directives.ySkew || regDataPtr->directives.zSkew)) {
        message("ERROR - Inconsistent parameters: (x,y,z)Rot and (x,y,z)Skew");
        return(ERROR);
    }
    if (regDataPtr->directives.xRot && (!regDataPtr->directives.zSqueeze)) {
        message("ERROR - Inconsistent parameters: xRot needs zSqueeze");
        return(ERROR);
    }
    if (regDataPtr->directives.yRot && (!regDataPtr->directives.zSqueeze)) {
        message("ERROR - Inconsistent parameters: yRot needs zSqueeze");
        return(ERROR);
    }
    message("STATUS - Initializing...");
    inPtr1 = regDataPtr->inPtr1;
    inPtr2 = regDataPtr->inPtr2;
    mskPtr1 = regDataPtr->inMsk1;
    mskPtr2 = regDataPtr->inMsk2;
    outPtr = regDataPtr->outPtr;
    mskPtr = regDataPtr->mskPtr;
    nx = regDataPtr->nx;
    ny = regDataPtr->ny;
    nz = regDataPtr->nz;
    initialEstimate(&fit, nx, ny, nz);
    if ((regDataPtr->directives.importFit != 0)
            && (regDataPtr->directives.convergence != gravity)) {
        if (importFit(&fit, regDataPtr->inFit) == ERROR) {
            message("ERROR - Importation of fit variables failed");
            return(ERROR);
        }
        switch (regDataPtr->directives.importFit) {
        case -1:
            if (invertFit(&fit, &invFit) == ERROR) {
                message("ERROR - Unable to compute the backward transformation");
                return(ERROR);
            }
            fit = invFit;
            break;
        case 1:
            break;
        default:
            message("ERROR - Unknown importFit specification");
            return(ERROR);
        }
    }
    switch (regDataPtr->directives.testMask) {
    case blank:
        u = mskPtr1;
        for (z = 0; (z < nz); z++)
            for (y = 0; (y < ny); y++)
                for (x = 0; (x < nx); u++, x++)
                    *u = 1.0F;
        break;
    case provided:
        break;
    case computed:
        if (maskFromData(inPtr1, mskPtr1, nx, ny, nz, regDataPtr->sx, regDataPtr->sy,
                         regDataPtr->sz) == ERROR) {
            message("ERROR - Unable to extract mask from test data");
            return(ERROR);
        }
        break;
    default:
        message("ERROR - Unknown test mask specification");
        return(ERROR);
    }
    switch (regDataPtr->directives.referenceMask) {
    case blank:
        u = mskPtr2;
        for (z = 0; (z < nz); z++)
            for (y = 0; (y < ny); y++)
                for (x = 0; (x < nx); u++, x++)
                    *u = 1.0F;
        break;
    case provided:
        break;
    case computed:
        if (maskFromData(inPtr2, mskPtr2, nx, ny, nz, regDataPtr->sx, regDataPtr->sy,
                         regDataPtr->sz) == ERROR) {
            message("ERROR - Unable to extract mask from reference data");
            return(ERROR);
        }
        break;
    default:
        message("ERROR - Unknown reference mask specification");
        return(ERROR);
    }
    if (regDataPtr->directives.zapMean) {
        mean = averageMskData(inPtr1, mskPtr1, nx, ny, nz);
        zapMean(inPtr1, mean, nx, ny, nz);
        mean = averageMskData(inPtr2, mskPtr2, nx, ny, nz);
        zapMean(inPtr2, mean, nx, ny, nz);
    }
    if ((!regDataPtr->directives.isoScaling) && (!regDataPtr->directives.xTrans)
            && (!regDataPtr->directives.yTrans) && (!regDataPtr->directives.zTrans)
            && (!regDataPtr->directives.xRot) && (!regDataPtr->directives.yRot)
            && (!regDataPtr->directives.zRot) && (!regDataPtr->directives.xSkew)
            && (!regDataPtr->directives.ySkew) && (!regDataPtr->directives.zSkew)
            && (!regDataPtr->directives.matchGrey)) {
        message("WARNING - Nothing to optimize");

        // We save the extracted transformation values to the ouptut structure used in the mex file.
        regDataPtr->fit.dx[0]=fit.dx[0];
        regDataPtr->fit.dx[1]=fit.dx[1];
        regDataPtr->fit.psi=fit.psi;
        regDataPtr->fit.skew[0][2]=fit.skew[0][2];
        regDataPtr->fit.skew[1][2]=fit.skew[1][2];
        regDataPtr->fit.skew[2][2]=fit.skew[2][2];
        regDataPtr->fit.skew[0][1]=fit.skew[0][1];
        regDataPtr->fit.skew[1][1]=fit.skew[1][1];
        regDataPtr->fit.skew[2][1]=fit.skew[2][1];
        regDataPtr->fit.skew[0][0]=fit.skew[0][0];
        regDataPtr->fit.skew[1][0]=fit.skew[1][0];
        regDataPtr->fit.skew[2][0]=fit.skew[2][0];

        regDataPtr->fit.origin[0]=fit.origin[0];
        regDataPtr->fit.origin[1]=fit.origin[1];
        message("STATUS - Creating output...");
        if (dirMskTransform(&fit, inPtr1, outPtr, mskPtr1, mskPtr, nx, ny, nz,
                            regDataPtr->directives.greyRendering, regDataPtr->directives.interpolation)
                == ERROR) {
            message("ERROR - Final transformation of test image failed");
            return(ERROR);
        }
        adornImage(outPtr, mskPtr, nx, ny, nz, nx, ny, nz, regDataPtr->directives.clipping,
                   regDataPtr->backgrnd);
        computeMskSnr(&mse, &snr, inPtr2, outPtr, mskPtr2, mskPtr,
                      regDataPtr->directives.maskCombine, nx, ny, nz);
        if (exportFit(&fit) == ERROR ) {
            message("ERROR - Assignment of transformation variables failed");
            return(ERROR);
        }
        if (exportSummary(&fit, mse, snr) == ERROR ) {
            message("ERROR - Assignment of summary variables failed");
            return(ERROR);
        }
        if (regDataPtr->directives.exportFit)
            if (fExportFit(&fit, regDataPtr->outFit) == ERROR ) {
                message("ERROR - Exportation of transformation variables failed");
                return(ERROR);
            }
        return(!ERROR);
    }
    bilevelFormat(mskPtr1, nx, ny, nz);
    bilevelFormat(mskPtr2, nx, ny, nz);
    if (regDataPtr->directives.convergence == gravity) {
        logicalFormat(mskPtr1, nx, ny, nz);
        logicalFormat(mskPtr2, nx, ny, nz);
        message("STATUS - Aligning centers of gravity...");
        if (getCenter(inPtr1, mskPtr1, nx, ny, nz, &x1, &y1, &z1) == ERROR) {
            message("ERROR - Unable to compute 1st center of gravity");
            return(ERROR);
        }
        if (getCenter(inPtr2, mskPtr2, nx, ny, nz, &x2, &y2, &z2) == ERROR) {
            message("ERROR - Unable to compute 2nd center of gravity");
            return(ERROR);
        }
        fit.dx[0] = x2 - x1;
        fit.dx[1] = y2 - y1;
        fit.dx[2] = z2 - z1;

        // We save the extracted transformation values to the ouptut structure used in the mex file.
        regDataPtr->fit.dx[0]=fit.dx[0];
        regDataPtr->fit.dx[1]=fit.dx[1];
        regDataPtr->fit.psi=fit.psi;
        regDataPtr->fit.skew[0][2]=fit.skew[0][2];
        regDataPtr->fit.skew[1][2]=fit.skew[1][2];
        regDataPtr->fit.skew[2][2]=fit.skew[2][2];
        regDataPtr->fit.skew[0][1]=fit.skew[0][1];
        regDataPtr->fit.skew[1][1]=fit.skew[1][1];
        regDataPtr->fit.skew[2][1]=fit.skew[2][1];
        regDataPtr->fit.skew[0][0]=fit.skew[0][0];
        regDataPtr->fit.skew[1][0]=fit.skew[1][0];
        regDataPtr->fit.skew[2][0]=fit.skew[2][0];

        regDataPtr->fit.origin[0]=fit.origin[0];
        regDataPtr->fit.origin[1]=fit.origin[1];

        message("STATUS - Creating output...");
        if (dirMskTransform(&fit, inPtr1, outPtr, mskPtr1, mskPtr, nx, ny, nz,
                            regDataPtr->directives.greyRendering, regDataPtr->directives.interpolation)
                == ERROR) {
            message("ERROR - Final transformation of test image failed");
            return(ERROR);
        }
        adornImage(outPtr, mskPtr, nx, ny, nz, nx, ny, nz, regDataPtr->directives.clipping,
                   regDataPtr->backgrnd);
        computeMskSnr(&mse, &snr, inPtr2, outPtr, mskPtr2, mskPtr,
                      regDataPtr->directives.maskCombine, nx, ny, nz);
        if (exportFit(&fit) == ERROR ) {
            message("ERROR - Assignment of transformation variables failed");
            return(ERROR);
        }
        if (exportSummary(&fit, mse, snr) == ERROR ) {
            message("ERROR - Assignment of summary variables failed");
            return(ERROR);
        }
        if (regDataPtr->directives.exportFit)
            if (fExportFit(&fit, regDataPtr->outFit) == ERROR ) {
                message("ERROR - Exportation of transformation variables failed");
                return(ERROR);
            }
        return(!ERROR);
    }
    for (l = 0; (l < regDataPtr->levels); l++) {
        pyrHdl1[l] = (float *)NULL;
        pyrHdl2[l] = (float *)NULL;
        mskHdl1[l] = (float *)NULL;
        mskHdl2[l] = (float *)NULL;
    }
    if (pyramid(mskPtr1, regDataPtr->levels, mskHdl1, nxRange, nyRange, nzRange, nx, ny, nz,
                regDataPtr->directives.zSqueeze, regDataPtr->directives.interpolation) == ERROR) {
        freePyramids(pyrHdl1, pyrHdl2, mskHdl1, mskHdl2, regDataPtr->levels);
        message("ERROR - Not enough memory for 1st mask pyramid computation");
        return(ERROR);
    }
    if (pyramid(mskPtr2, regDataPtr->levels, mskHdl2, nxRange, nyRange, nzRange, nx, ny, nz,
                regDataPtr->directives.zSqueeze, regDataPtr->directives.interpolation) == ERROR) {
        freePyramids(pyrHdl1, pyrHdl2, mskHdl1, mskHdl2, regDataPtr->levels);
        message("ERROR - Not enough memory for 2nd mask pyramid computation");
        return(ERROR);
    }
    logicalFormat(mskPtr1, nx, ny, nz);
    logicalFormat(mskPtr2, nx, ny, nz);
    for (l = 0; (l < regDataPtr->levels); l++) {
        logicalFormat(mskHdl1[l], (int)nxRange[l], (int)nyRange[l], (int)nzRange[l]);
        logicalFormat(mskHdl2[l], (int)nxRange[l], (int)nyRange[l], (int)nzRange[l]);
    }
    if (pyramid(inPtr1, regDataPtr->levels, pyrHdl1, nxRange, nyRange, nzRange, nx, ny, nz,
                regDataPtr->directives.zSqueeze, regDataPtr->directives.interpolation) == ERROR) {
        freePyramids(pyrHdl1, pyrHdl2, mskHdl1, mskHdl2, regDataPtr->levels);
        message("ERROR - Not enough memory for 1st pyramid computation");
        return(ERROR);
    }
    if (pyramid(inPtr2, regDataPtr->levels, pyrHdl2, nxRange, nyRange, nzRange, nx, ny, nz,
                regDataPtr->directives.zSqueeze, regDataPtr->directives.interpolation) == ERROR ) {
        freePyramids(pyrHdl1, pyrHdl2, mskHdl1, mskHdl2, regDataPtr->levels);
        message("ERROR - Not enough memory for 2nd pyramid computation");
        return(ERROR);
    }
    epsilon[0] = regDataPtr->epsilon;
    switch (regDataPtr->directives.convergence) {
    case Marquardt:
        for (l = 1; (l < regDataPtr->levels); l++)
            epsilon[l] = epsilon[l - 1];
        break;
    default:
        freePyramids(pyrHdl1, pyrHdl2, mskHdl1, mskHdl2, regDataPtr->levels);
        message("ERROR - Unknown convergence");
        return(ERROR);
    }
    message("STATUS - Optimizing...");
    origin[0] = (double)((nxRange[0] - 1L) / 2L);
    origin[1] = (double)((nyRange[0] - 1L) / 2L);
    origin[2] = (double)((nzRange[0] - 1L) / 2L);
    convertOrigin(&fit, origin);
    for (l = 0; (l < (regDataPtr->levels - 1)); l++)
        downscaleFit(&fit, nxRange, nyRange, nzRange, l, regDataPtr->directives.zSqueeze);
    lambda = regDataPtr->firstLambda;
    for (l = regDataPtr->levels - 1; (l >= 0); l--) {
        if ((l == (regDataPtr->levels - 1)) || (l >= (regDataPtr->lastLevel - 1))) {
            ia[0] = regDataPtr->directives.xTrans;							/* dx[0] */
            ia[1] = regDataPtr->directives.yTrans && (nyRange[l] != 1L);	/* dx[1] */
            ia[2] = regDataPtr->directives.zTrans && (nzRange[l] != 1L);	/* dx[2] */
            for (k = 3; (k < 12); k++)
                ia[k] = FALSE;
            ia[12] = regDataPtr->directives.matchGrey;						/* gamma */
            if (regDataPtr->directives.xSkew) {
                ia[3] = TRUE;													/* skew[0][0] */
                ia[6] = (nyRange[l] != 1L);									/* skew[1][0] */
                ia[9] = (nzRange[l] != 1L);									/* skew[2][0] */
            }
            if (regDataPtr->directives.ySkew) {
                ia[4] = (nyRange[l] != 1L);									/* skew[0][1] */
                ia[7] = (nyRange[l] != 1L);									/* skew[1][1] */
                ia[10] = (nzRange[l] != 1L);									/* skew[2][1] */
            }
            if (regDataPtr->directives.zSkew) {
                ia[5] = (nzRange[l] != 1L);									/* skew[0][2] */
                ia[8] = (nzRange[l] != 1L);									/* skew[1][2] */
                ia[11] = (nzRange[l] != 1L);									/* skew[2][2] */
            }
            if (regDataPtr->directives.xRot || regDataPtr->directives.yRot
                    || regDataPtr->directives.zRot || regDataPtr->directives.isoScaling) {
                ia[3] = regDataPtr->directives.xRot && (nyRange[l] != 1L);	/* phi */
                ia[4] = regDataPtr->directives.yRot && (nzRange[l] != 1L);	/* theta */
                ia[5] = regDataPtr->directives.zRot && (nyRange[l] != 1L);	/* psi */
                ia[6] = regDataPtr->directives.isoScaling;					/* lambda */
                ia[7] = regDataPtr->directives.matchGrey;						/* gamma */
                ia[8] = FALSE;
                ia[9] = FALSE;
                ia[10] = FALSE;
                ia[11] = FALSE;
                ia[12] = FALSE;
            }
            switch (regDataPtr->directives.convergence) {
            case Marquardt:
                if (optimize(&fit, &(regDataPtr->directives), ia, pyrHdl1[l], pyrHdl2[l],
                             mskHdl1[l], mskHdl2[l], outPtr, mskPtr, &lambda, regDataPtr->firstLambda,
                             regDataPtr->lambdaScale, epsilon[l], regDataPtr->minGain,
                             (int)nxRange[l], (int)nyRange[l], (int)nzRange[l]) == ERROR) {
                    freePyramids(pyrHdl1, pyrHdl2, mskHdl1, mskHdl2, regDataPtr->levels);
                    message("ERROR - Optimization failed (Marquardt)");
                    return(ERROR);
                }
                lambda = regDataPtr->firstLambda;
                break;
            default:
                freePyramids(pyrHdl1, pyrHdl2, mskHdl1, mskHdl2, regDataPtr->levels);
                message("ERROR - Unknown convergence");
                return(ERROR);
            }
        }
        if (l != 0)
            upscaleFit(&fit, nxRange, nyRange, nzRange, l, regDataPtr->directives.zSqueeze);
    }
    convertOrigin(&fit, origin);

    // We save the extracted transformation values to the ouptut structure used in the mex file.
    regDataPtr->fit.dx[0]=fit.dx[0];
    regDataPtr->fit.dx[1]=fit.dx[1];

    regDataPtr->fit.psi=fit.psi;

    regDataPtr->fit.skew[0][2]=fit.skew[0][2];
    regDataPtr->fit.skew[1][2]=fit.skew[1][2];
    regDataPtr->fit.skew[2][2]=fit.skew[2][2];
    regDataPtr->fit.skew[0][1]=fit.skew[0][1];
    regDataPtr->fit.skew[1][1]=fit.skew[1][1];
    regDataPtr->fit.skew[2][1]=fit.skew[2][1];
    regDataPtr->fit.skew[0][0]=fit.skew[0][0];
    regDataPtr->fit.skew[1][0]=fit.skew[1][0];
    regDataPtr->fit.skew[2][0]=fit.skew[2][0];

    regDataPtr->fit.origin[0]=fit.origin[0];
    regDataPtr->fit.origin[1]=fit.origin[1];

    message("STATUS - Creating output...");
    if (dirMskTransform(&fit, inPtr1, outPtr, mskPtr1, mskPtr, nx, ny, nz,
                        regDataPtr->directives.greyRendering, regDataPtr->directives.interpolation) == ERROR) {
        freePyramids(pyrHdl1, pyrHdl2, mskHdl1, mskHdl2, regDataPtr->levels);
        message("ERROR - Final transformation of test image failed");
        return(ERROR);
    }
    adornImage(outPtr, mskPtr, nx, ny, nz, (int)nxRange[0], (int)nyRange[0],
               (int)nzRange[0], regDataPtr->directives.clipping, regDataPtr->backgrnd);
    computeMskSnr(&mse, &snr, inPtr2, outPtr, mskPtr2, mskPtr,
                  regDataPtr->directives.maskCombine, nx, ny, nz);
    if (exportFit(&fit) == ERROR ) {
        freePyramids(pyrHdl1, pyrHdl2, mskHdl1, mskHdl2, regDataPtr->levels);
        message("ERROR - Assignment of transformation variables failed");
        return(ERROR);
    }
    if (exportSummary(&fit, mse, snr) == ERROR ) {
        freePyramids(pyrHdl1, pyrHdl2, mskHdl1, mskHdl2, regDataPtr->levels);
        message("ERROR - Assignment of summary variables failed");
        return(ERROR);
    }
    if (regDataPtr->directives.exportFit)
        if (fExportFit(&fit, regDataPtr->outFit) == ERROR ) {
            freePyramids(pyrHdl1, pyrHdl2, mskHdl1, mskHdl2, regDataPtr->levels);
            message("ERROR - Exportation of transformation variables failed");
            return(ERROR);
        }
    freePyramids(pyrHdl1, pyrHdl2, mskHdl1, mskHdl2, regDataPtr->levels);
    return(!ERROR);
} /* End of regFloat3d */
예제 #20
0
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   const double len=2000;  //  Length of axes

   float Position[] = {X+700*Cos(Th)-400,Y+50*Sin(Th),300+Z+1200*Sin(Th),1-inf};
   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
   //  Enable Z-buffering in OpenGL
   glEnable(GL_DEPTH_TEST);
   //  Undo previous transformations
   glLoadIdentity();
   //  Perspective - set eye position
   if (mode)
   {
      double Ex = -2*dim*Sin(th)*Cos(ph);
      double Ey = +2*dim        *Sin(ph);
      double Ez = +2*dim*Cos(th)*Cos(ph);
      gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0);
   }
   //  Orthogonal - set world orientation
   else
   {
      glRotatef(ph,1,0,0);
      glRotatef(th,0,1,0);
   }
   glShadeModel(smooth?GL_SMOOTH:GL_FLAT);
   //  Light switch
   if (light)
   {
      //  Translate intensity to color vectors
      float Ambient[]   = {0.01*ambient ,0.01*ambient ,0.01*ambient ,1.0};
      float Diffuse[]   = {0.01*diffuse ,0.01*diffuse ,0.01*diffuse ,1.0};
      float Specular[]  = {0.01*specular,0.01*specular,0.01*specular,1.0};
      //  Spotlight color and direction
      float yellow[] = {1.0,1.0,0.0,1.0};
      float Direction[] = {Cos(Th)*Sin(Ph),Sin(Th)*Sin(Ph),-Cos(Ph),0};
      //  Draw light position as ball (still no lighting here)
      ball(Position[0],Position[1],Position[2] , 10);
      //  OpenGL should normalize normal vectors
      glEnable(GL_NORMALIZE);
      //  Enable lighting
      glEnable(GL_LIGHTING);
      //  Location of viewer for specular calculations
      glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,local);
      //  Two sided mode
      glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,side);
      //  glColor sets ambient and diffuse color materials
      glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
      glEnable(GL_COLOR_MATERIAL);
      //  Set specular colors
      glMaterialfv(GL_FRONT,GL_SPECULAR,yellow);
      glMaterialfv(GL_FRONT,GL_SHININESS,shinyvec);
      //  Enable light 0
      glEnable(GL_LIGHT0);
      //  Set ambient, diffuse, specular components and position of light 0
      glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient);
      glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse);
      glLightfv(GL_LIGHT0,GL_SPECULAR,Specular);
      glLightfv(GL_LIGHT0,GL_POSITION,Position);
      //  Set spotlight parameters
      glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,Direction);
      glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,sco);
      glLightf(GL_LIGHT0,GL_SPOT_EXPONENT,Exp);
      //  Set attenuation
      glLightf(GL_LIGHT0,GL_CONSTANT_ATTENUATION ,at0/100.0);
      glLightf(GL_LIGHT0,GL_LINEAR_ATTENUATION   ,at1/100.0);
      glLightf(GL_LIGHT0,GL_QUADRATIC_ATTENUATION,at2/100.0);
   }
   else
      glDisable(GL_LIGHTING);
   //  Enable textures
   if (ntex)
      glEnable(GL_TEXTURE_2D);
   else
      glDisable(GL_TEXTURE_2D);
   glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
   


   // drawing the 3 great pyramids of Egypt
      pyramid(0,0,0,      230.124,138.684,230.124, 0);
       
      pyramid(300,0,115,  30,30,30, 0);
      pyramid(300,0,20,  30,30,30, 0);
      pyramid(300,0,-75,  30,30,30, 0);

      pyramid(-500,0,600, 230,136,230, 0);

      cube(-100, 0, 600, 115, 30, 50, 0);
      // sphere2(-20, 90, 600, 30);

      pyramid(-900,0,990, 103.327,60.96,103.327, 0);
      
      // drawig the queens' pyramids
      pyramid(-900,0, 1200, 30, 30, 30, 0);
      pyramid(-1000,0, 1200, 30, 30, 30, 0);
      pyramid(-800,0, 1200, 30, 30, 30, 0);
   


   glDisable(GL_TEXTURE_2D);
   //  Draw axes - no lighting from here on
   glDisable(GL_LIGHTING);
   glColor3f(1,1,1);
   if (axes)
   {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
   }
   //  Display parameters
   glWindowPos2i(5,5);
   Print("Angle=%d,%d  Dim=%.1f Projection=%s Light=%s",
     th,ph,dim,mode?"Orthogonal":"Perpective",light?"On":"Off");
   if (light)
   {
      glWindowPos2i(5,65);
      Print("Cutoff=%.0f Exponent=%.1f Direction=%d,%d Attenuation=%.2f,%.2f,%.2f",sco,Exp,Th,Ph,at0/100.0,at1/100.0,at2/100.0);
      glWindowPos2i(5,45);
      Print("Model=%s LocalViewer=%s TwoSided=%s Position=%.1f,%.1f,%.1f,%.1f",smooth?"Smooth":"Flat",local?"On":"Off",side?"On":"Off",Position[0],Position[1],Position[2],Position[3]);
      glWindowPos2i(5,25);
      Print("Ambient=%d  Diffuse=%d Specular=%d Emission=%d Shininess=%.0f",ambient,diffuse,specular,emission,shinyvec[0]);
   }
   //  Render the scene and make it visible
   ErrCheck("display");
   glFlush();
   glutSwapBuffers();
}
int main(int argc, char** argv)
{
  std::cout << "Starting iu_imagepyramid_gpu_unittest ..." << std::endl;

  if(argc < 2)
  {
    std::cout << "You have to provide at least a filename for reading an image." << std::endl;
    exit(EXIT_FAILURE);
  }
  const std::string filename = argv[1];

  std::cout << "reading image " << filename << std::endl;
  iu::ImageGpu_32f_C1* image = iu::imread_cu32f_C1(filename);
  std::cout << "image pixel_type = " << image->pixelType() << std::endl;

  iu::imshow(image, "original input");

  unsigned int levels = 100;
  iu::ImagePyramid pyramid(levels, image->size(), 0.8f, 32);

  std::cout << "#levels changed to " << levels << " to fit the pyramid" << std::endl;

  std::stringstream stream;
  std::string winname;

  std::cout << "--pyramid pixel type = " << pyramid.pixelType() << std::endl;
  pyramid.setImage(image);
  std::cout << "--pyramid pixel type = " << pyramid.pixelType() << std::endl;

//  iu::copy(image, reinterpret_cast<iu::ImageGpu_32f_C1*>(pyramid.image(0)));
//  iu::imshow(reinterpret_cast<iu::ImageGpu_32f_C1*>(pyramid.image(0)), "level 0");

  double time = iu::getTime();
  std::cout << "num_levels=" << pyramid.numLevels() << std::endl;

//  std::cout << "level " << 0 << ": size=" << pyramid.size(0).width << "/" << pyramid.size(0).height
//            << "; rate=" << pyramid.scaleFactor(0) << std::endl;


  std::cout << "image pixel type = " << image->pixelType() << std::endl;
  std::cout << "pyramid pixel type = " << pyramid.pixelType() << std::endl;

  // print all the created level sizes:
  for(unsigned int i=0; i<pyramid.numLevels(); ++i)
  {
    std::cout << "level " << i << ":" << std::endl;

    std::cout << "  size=" << pyramid.size(i).width << "/" << pyramid.size(i).height
              << "; rate=" << pyramid.scaleFactor(i) << std::endl;

    stream.clear();
    stream << "level " << i;
    winname = stream.str();
    iu::imshow(pyramid.imageGpu_32f_C1(i), winname);
  }

  time = iu::getTime() - time;
  std::cout << "time for building imagepyramid = " << time << "ms" << std::endl;

  cv::waitKey();

  std::cout << std::endl;
  std::cout << "**************************************************************************" << std::endl;
  std::cout << "*  Everything seem to be ok. -- All assertions passed.                   *" << std::endl;
  std::cout << "*  Look at the images and close the windows to derminate the unittests.  *" << std::endl;
  std::cout << "**************************************************************************" << std::endl;
  std::cout << std::endl;

  return EXIT_SUCCESS;
}
예제 #22
0
파일: main.cpp 프로젝트: NIA/D3DLighting
INT WINAPI wWinMain( HINSTANCE, HINSTANCE, LPWSTR, INT )
{
    srand( static_cast<unsigned>( time(NULL) ) );
    
    SkinningVertex * cylinder_vertices = NULL;
    Index * cylinder_indices = NULL;
    Vertex * tesselated_vertices = NULL;
    Index * tesselated_indices = NULL;
    try
    {
        Application app;

        VertexShader skinning_shader(app.get_device(), SKINNING_VERTEX_DECL_ARRAY, SKINNING_SHADER_FILENAME);
        VertexShader morphing_shader(app.get_device(), VERTEX_DECL_ARRAY, MORPHING_SHADER_FILENAME);
        
        // -------------------------- C y l i n d e r -----------------------

        cylinder_vertices = new SkinningVertex[CYLINDER_VERTICES_COUNT];
        cylinder_indices = new Index[CYLINDER_INDICES_COUNT];

        float height = 2.0f;
        cylinder( 0.7f, height,
                  colors, colors_count,
                  cylinder_vertices, cylinder_indices );

        SkinningModel cylinder1(app.get_device(),
                                D3DPT_TRIANGLESTRIP,
                                skinning_shader,
                                cylinder_vertices,
                                CYLINDER_VERTICES_COUNT,
                                cylinder_indices,
                                CYLINDER_INDICES_COUNT,
                                CYLINDER_INDICES_COUNT - 2,
                                D3DXVECTOR3(0.5f, 0.5f, -height/2),
                                D3DXVECTOR3(0,0,0),
                                D3DXVECTOR3(0,0,-1));

        height = 2.3f;
        cylinder( 0.3f, height,
                  &SECOND_CYLINDER_COLOR, 1,
                  cylinder_vertices, cylinder_indices );

        SkinningModel cylinder2(app.get_device(),
                                D3DPT_TRIANGLESTRIP,
                                skinning_shader,
                                cylinder_vertices,
                                CYLINDER_VERTICES_COUNT,
                                cylinder_indices,
                                CYLINDER_INDICES_COUNT,
                                CYLINDER_INDICES_COUNT - 2,
                                D3DXVECTOR3(-1.0f, 0.5f, height/2),
                                D3DXVECTOR3(D3DX_PI,0,-D3DX_PI/4),
                                D3DXVECTOR3(0,0,1));

        
        // -------------------------- P y r a m i d -----------------------
        const Index PLANES_PER_PYRAMID = 8;
        const D3DXVECTOR3 normal_up(0,0,1);
        const Vertex pyramid_vertices[]=
        {
            Vertex(D3DXVECTOR3(  0.5f, -0.5f,  0.00f ),normal_up),
            Vertex(D3DXVECTOR3( -0.5f, -0.5f,  0.00f ),normal_up),
            Vertex(D3DXVECTOR3( -0.5f,  0.5f,  0.00f ),normal_up),
            Vertex(D3DXVECTOR3(  0.5f,  0.5f,  0.00f ),normal_up),
            Vertex(D3DXVECTOR3(  0.0f,  0.0f,  0.7071f ),normal_up),
            Vertex(D3DXVECTOR3(  0.0f,  0.0f, -0.7071f ),normal_up),
        };
        const Index pyramid_indices[PLANES_PER_PYRAMID*VERTICES_PER_TRIANGLE] =
        {
            0, 4, 3,
            3, 4, 2,
            2, 4, 1,
            1, 4, 0,

            0, 3, 5,
            3, 2, 5,
            2, 1, 5,
            1, 0, 5,
        };

        const Index ALL_TESSELATED_VERTICES_COUNT = PLANES_PER_PYRAMID*TESSELATED_VERTICES_COUNT; // per 8 tessellated triangles
        const DWORD ALL_TESSELATED_INDICES_COUNT = PLANES_PER_PYRAMID*TESSELATED_INDICES_COUNT; // per 8 tessellated triangles

        tesselated_vertices = new Vertex[ALL_TESSELATED_VERTICES_COUNT];
        tesselated_indices = new Index[ALL_TESSELATED_INDICES_COUNT];

        for( DWORD i = 0; i < PLANES_PER_PYRAMID; ++i )
        {
            tessellate( pyramid_vertices, pyramid_indices, i*VERTICES_PER_TRIANGLE,
                        &tesselated_vertices[i*TESSELATED_VERTICES_COUNT], i*TESSELATED_VERTICES_COUNT,
                        &tesselated_indices[i*TESSELATED_INDICES_COUNT], SPHERE_COLOR );
        }
        
        MorphingModel pyramid( app.get_device(),
                               D3DPT_TRIANGLELIST,
                               morphing_shader,
                               tesselated_vertices,
                               ALL_TESSELATED_VERTICES_COUNT,
                               tesselated_indices,
                               ALL_TESSELATED_INDICES_COUNT,
                               ALL_TESSELATED_INDICES_COUNT/VERTICES_PER_TRIANGLE,
                               D3DXVECTOR3(0, -1.3f, -0.2f),
                               D3DXVECTOR3(0,0,0),
                               0.7071f);

        app.add_model(cylinder1);
        app.add_model(cylinder2);
        app.add_model(pyramid);
        app.run();
        delete_array(&tesselated_indices);
        delete_array(&tesselated_vertices);
        delete_array(&cylinder_indices);
        delete_array(&cylinder_vertices);
    }
    catch(RuntimeError &e)
    {
        delete_array(&tesselated_indices);
        delete_array(&tesselated_vertices);
        delete_array(&cylinder_indices);
        delete_array(&cylinder_vertices);
        const TCHAR *MESSAGE_BOX_TITLE = _T("Lighting error!");
        MessageBox(NULL, e.message(), MESSAGE_BOX_TITLE, MB_OK | MB_ICONERROR);
        return -1;
    }
    return 0;
}
예제 #23
0
  void OstreamGMV3DFmt::StaticData::initialize()
{
  if(archetypes == 0 || names == 0) {
    archetypes = new archetype_table;
    names      = new archetype_name_map;

    // construct tet
    int conn_tet[4*4] = {
      3,  0, 1, 2,
      3,  0, 3, 1,
      3,  0, 2, 3,
      3,  1, 3, 2
    };
    stream_grid_mask<int *> tet(4,4,conn_tet); 
    archetypes->push_back(archetype_type());
    ConstructGrid0(archetypes->back(), tet);
    (*names)[archetypes->size() -1] = "tet";
    
    // construct hex
    
    // 0: (0,0,0), 1: (1,0,0), 2: (1,1,0), 3: (0,1,0)
    // 4: (0,0,1), 5: (1,0,1), 6: (1,1,1), 7: (0,1,1)
    
    int conn_hex[5*6] = {
      4,  0, 3, 2, 1,
      4,  0, 1, 5, 4,
      4,  0, 4, 7, 3,
      4,  1, 2, 6, 5,
      4,  2, 3, 7, 6,
      4,  4, 5, 6, 7
    };
    stream_grid_mask<int *> hex(8,6,conn_hex); 
    archetypes->push_back(archetype_type());
    ConstructGrid0(archetypes->back(), hex);
    (*names)[archetypes->size()-1] = "phex8";

    // construct prism
    int conn_prism[3*5+2*4] = {
      3, 0, 1, 2,
      3, 3, 5, 4,
      4, 0, 3, 4, 1,
      4, 1, 4, 5, 2,
      4, 0, 2, 5, 3
    };
    stream_grid_mask<int *> prism(6,5,conn_prism); 
    archetypes->push_back(archetype_type());
    ConstructGrid0(archetypes->back(), prism);
    (*names)[archetypes->size()-1] = "prism";
    
    
    // construct pyramid
    int conn_pyramid[1*5+4*4] = {
      4,  4, 3, 2, 1,
      3,  0, 1, 2,
      3,  0, 2, 3,
      3,  0, 3, 4,
      3,  0, 4, 1
    };
    stream_grid_mask<int *> pyramid(5,5,conn_pyramid); 
    archetypes->push_back(archetype_type());
    ConstructGrid0(archetypes->back(), pyramid);
    (*names)[archetypes->size() -1] = "pyramid";

    //  cerr << Printer(*names) << '\n';
  }
}
예제 #24
0
/**
 *  The example test program creates two pyramid graphs and produces
 *  the OR-product graph of them.  Then it prints the DOT
 *  representation of such graphs.
 *
 */
int main(int argc, char *argv[])
{

  int pebbling_bound=0;

  int pyramid_height=0;
  int tree_height=0;
  int chain_length=0;
  
  FILE *input_file=NULL;

  int input_directives = 0;
  char graph_name[100];
  
  int option_code=0;

  /* Parse option to set Pyramid height,
     pebbling upper bound. */
  while((option_code = getopt(argc,argv,"hb:p:2:c:f:i:g:"))!=-1) {
    switch (option_code) {
    case 'h':
      fprintf(stderr,USAGEMESSAGE,argv[0]);
      exit(EXIT_SUCCESS);
      break;
    case 'b':
      pebbling_bound=atoi(optarg);
      if (pebbling_bound>0) break;
      fprintf(stderr,USAGEMESSAGE,argv[0]);
      exit(EXIT_FAILURE);
      break;
    /* Input */
    case 'p':
      pyramid_height=atoi(optarg);
      if (pyramid_height>0) {input_directives++; break;}
      fprintf(stderr,USAGEMESSAGE,argv[0]);
      exit(EXIT_FAILURE);
      break;
    case '2':
      tree_height=atoi(optarg);
      if (tree_height>0) {input_directives++; break;}
      fprintf(stderr,USAGEMESSAGE,argv[0]);
      exit(EXIT_FAILURE);
      break;
    case 'c':
      chain_length=atoi(optarg);
      if (chain_length>0) {input_directives++; break;}
      fprintf(stderr,USAGEMESSAGE,argv[0]);
      exit(EXIT_FAILURE);
      break;
    case 'i':
      input_file=openinputfile(optarg);
      input_directives++;
      break;
    case '?':
    default:
      fprintf(stderr,USAGEMESSAGE,argv[0]);
      exit(EXIT_FAILURE);
    }
  }

  /* Test for valid command line */
  if (pebbling_bound==0) {
      fprintf(stderr,USAGEMESSAGE,argv[0]);
      exit(EXIT_FAILURE);
  }

  /* Only one input */
  if (input_directives > 1) {
    fprintf(stderr,USAGEMESSAGE,argv[0]);
    exit(EXIT_FAILURE);
  } 
  if (input_directives == 0) input_file = stdin;

  
  /* Produce or read input graph */
  DAG *C=NULL;
  if (pyramid_height>0) {
  
    C=pyramid(pyramid_height);
    snprintf(graph_name, 100, "Pyramid of height %d",pyramid_height);
  
  } else if (tree_height>0) {
    
    C=tree(tree_height);
    snprintf(graph_name, 100, "Tree of height %d",tree_height);
  
  } else if (chain_length>0) {
    
    C=path(chain_length);
    snprintf(graph_name, 100, "Chain of height %d",chain_length);

  } else {
    C=kthparser(input_file);
    fclose(input_file);
    snprintf(graph_name, 100, "Input graph");
  }

  /* Re-output the input graph */
  printf("c ===== input DAG ======\n");
  printf("c c %s\n", graph_name);
  fprint_DAG(stdout,C,"c ");
  printf("c ======================\n");
  printf("c Dymon-Tompa rounds: %d\n", pebbling_bound);
  printf("c ======================\n");
  
  /* Output the QBF */

  /* Clean up and exit */
  dispose_DAG(C);
  exit(EXIT_SUCCESS);
}