Exemplo n.º 1
0
void renderObjects()
{
	// Set Modeling transformation for the reference plane
	modelingTransformation = glm::translate(glm::vec3(0.0f, -3.0f, 0.0f));
	refPlane.draw();

	// Set modeling transformation for the front left pyramid
	modelingTransformation = glm::translate(glm::vec3(-3.5f, -2.5f, 3.5f));
	pyramid.draw(color(0.0f, 0.0f, 1.0f, 1.0f));

	// Set modeling transformation for the back right pyramid
	modelingTransformation = glm::translate(glm::vec3(3.5f, -2.5f, -3.5f));
	pyramid.draw(color(0.0f, 0.0f, 1.0f, 1.0f));

	// Set modeling transformation for the center pyramid
	modelingTransformation = glm::translate(glm::vec3(0.0f, 0.0f, 0.0f)) * glm::rotate(angle, glm::vec3(0.0f, 1.0f, 0.0f));
	pyramid.draw(color(1.0f, 0.0f, 0.0f, 1.0f));

	// Set modeling transformation for the right hand pyramid
	modelingTransformation = glm::translate(glm::vec3(3.0f, 0.0f, 0.0f)) * glm::rotate(angle, glm::vec3(1.0f, 0.0f, 0.0f));
	sphere.draw(color(1.0f, 1.0f, 0.0f, 1.0f));

	// Set modeling transformation for the left hand pyramid
	modelingTransformation = glm::translate(glm::vec3(-3.0f, 0.0f, 0.0f)) * glm::rotate(angle, glm::vec3(0.0f, 0.0f, 1.0f)) * glm::scale(glm::vec3(2.0f, 2.0f, 2.0f));
	pyramid.draw(color(1.0f, 0.0f, 1.0f, 1.0f));

}
Exemplo n.º 2
0
void create_pyramid(const Parameters &params, Pyramid &pyr,
                    const rod::dimage<float3> &img0,
                    const rod::dimage<float3> &img1)
{
    rod::base_timer &timer_total = rod::timers.gpu_add("Pyramid creation");

    size_t nlevels 
        = log2(std::min(img0.width(),img0.height())) - log2(params.start_res)+1;

    rod::base_timer *timer 
        = &rod::timers.gpu_add("level 0",img0.width()*img0.height(),"P");

    rod::dimage<float> luma0(img0.width(),img0.height()), 
                       luma1(img1.width(),img1.height());

    PyramidLevel &lvl0 = pyr.append_new(img0.width(), img0.height());

    luminance(&luma0, &img0);
    luminance(&luma1, &img1);

    copy_to_array(lvl0.img0, &luma0);
    copy_to_array(lvl0.img1, &luma1);

    timer->stop();

    int base_level = 0;

    for(int l=1; l<nlevels; ++l)
    {
        int w = round(img0.width()/((float)(1<<l))),
            h = round(img0.height()/((float)(1<<l)));

        std::clog << "Level " << l << ": " << w << "x" << h << std::endl;

        std::ostringstream ss;
        ss << "level " << l;

        rod::scoped_timer_stop sts(rod::timers.gpu_add(ss.str(), w*h,"P"));

        PyramidLevel &lvl = pyr.append_new(w,h);

        while((float)pyr[base_level].width/w * pyr[base_level].height/h>=1024)
            ++base_level;

        luma0.resize(w,h);
        luma1.resize(w,h);

        downsample(&luma0, pyr[base_level].img0, 
                   pyr[base_level].width, pyr[base_level].height);
        downsample(&luma1, pyr[base_level].img1,
                   pyr[base_level].width, pyr[base_level].height);

        copy_to_array(lvl.img0, &luma0);
        copy_to_array(lvl.img1, &luma1);
    }

    timer_total.stop();
}
Exemplo n.º 3
0
number CalculateVolume(const Pyramid& pyramid,
		Grid::VertexAttachmentAccessor<APosition>& aaPos) {
	vector3& a = aaPos[pyramid.vertex(0)];
	vector3& b = aaPos[pyramid.vertex(1)];
	vector3& c = aaPos[pyramid.vertex(2)];
	vector3& d = aaPos[pyramid.vertex(3)];
	vector3& top = aaPos[pyramid.vertex(4)];

	return CalculateVolumePyramid(a, b, c, d, top);
}
Exemplo n.º 4
0
int main() {
	sf::ContextSettings set;
	set.antialiasingLevel = 8;
	sf::Window w(sf::VideoMode(700, 700), "ogl", sf::Style::Default, set);
	glewExperimental = true;
	glewInit();
	Context gl;
	gl.ClearColor(0.0, 0.0, 0.0, 1.0);
	gl.Enable(Capability::DepthTest);
	gl.Enable(Capability::CullFace);
	gl.Enable(Capability::Blend);
	w.setMouseCursorVisible(false);

	Pyramid pyramid { w };

	bool running = true;
	while(running) {
		sf::Event e;
		while(w.pollEvent(e)){
			if(e.type == sf::Event::Closed){ running = false; }
			if(e.type == sf::Event::KeyPressed) {
				switch(e.key.code) {
				case sf::Keyboard::Escape:
					running = false;
					break;
				case sf::Keyboard::W: case sf::Keyboard::Up:
					camera.forward();
					break;
				case sf::Keyboard::A: case sf::Keyboard::Left:
					camera.left();
					break;
				case sf::Keyboard::S: case sf::Keyboard::Down:
					camera.back();
					break;
				case sf::Keyboard::D: case sf::Keyboard::Right:
					camera.right();
					break;
				default:
					break;
				}
				}
			if(e.type == sf::Event::MouseMoved) {
					//idk
			}
		}

		pyramid.update();
		pyramid.draw(gl);
		gl.Clear().ColorBuffer().DepthBuffer();
		w.display();
	}
	return 0;
}
Exemplo n.º 5
0
Ogre::ManualObject* BlockFactory::createBlock(
	Map::PrintType cellType,
	unsigned int i,
	unsigned int j,
	double scale
) {

	stringstream genName;
	genName << "manualBlock_" << i << "_" << j;

	switch (cellType) {
		case Map::EMPTY:
			return NULL;
			break;
		case Map::BREAKABLE: {
			Pyramid *myPyramid = new Pyramid(
				mSceneMgr->createManualObject(genName.str()),
				Block::COMPLETE,
				-(scale/2),
				-(scale/6),
				-(scale/2),
				scale,
				scale/2,
				scale
			);
			return myPyramid->GetManualBlock();
			break;
		}
		case Map::UNBREAKABLE: {
			Cube *myCube = new Cube(
				mSceneMgr->createManualObject(genName.str()),
				Block::COMPLETE,
				-(scale/2),
				-(scale/6),
				-(scale/2),
				scale,
				scale/3,
				scale
			);
			return myCube->GetManualBlock();
			break;
		}
		default:
			break;
	}

	//TODO Exception?
	Ogre::LogManager::getSingletonPtr()->logMessage("WARNING No representation for this kind of Block");
	std::cerr << cellType << std::endl;
	return NULL;
}
Exemplo n.º 6
0
void Microphone::setUprightHeight (float h) {
	float shift = h - uH;
	tH += shift; uH = tH * 0.58436f;

	Cone			upright	 (uH * 0.21127f + 2 * uG, uR * 0.66667f, uR * 0.66667f, 24),
					shroudLow(uH * 0.21127f, uR, uR, 24),
					shroudHi (uH - upright.getHeight() - uH * 0.084537f, uR, uR, 24),
					bridge   (uH * 0.084537f,uR * 0.66667f, uR * 0.41667f, 24);

	Pyramid			handleBridgeUp	(uH * 0.09155f, uR * 0.653f, hI, uR * 0.653f, hI),
					handleBridgeDown(uH * 0.077f,   uR * 0.653f, hI, uR * 0.653f, hI),
					handle			(uH * 0.7598f,  uR * 0.792f, uR * 0.5418f, uR * 0.5418f, uR * 0.5418f, uR * 0.125f),
					handleTop		(uH * 0.05647f, uR * 0.792f, uR * 0.5418f, uR * 0.792f,  uR * 0.5418f,-uR * 0.3542f);

	upright.Fly(bH);
	shroudLow.Fly(tH * 0.0823f);
	shroudHi.Fly(shroudLow.getPosition().z + shroudLow.getHeight() + uG);
	bridge.Fly(shroudHi.getPosition().z + shroudHi.getHeight());

	handleBridgeUp.Fly(tH * 0.46f);
	handleBridgeUp.Follow(bR * 0.2f);
	handleBridgeDown.Fly(tH * 0.15f);
	handleBridgeDown.Follow(handleBridgeUp.getPosition().x);
	handle.Translate(bR * 0.306f, bR * 0.0059f, tH * 0.547f);
	handle.Pitch((FLOAT)M_PI);
	handle.Yaw((FLOAT)M_PI_2);
	handleTop.Translate(handle.getPosition().x, handle.getPosition().y, handle.getPosition().z);
	handleTop.Yaw((FLOAT)M_PI_2);

	replaceMesh(MIC_UPRIGHT, upright);
	replaceMesh(MIC_SHROUD_LOW, shroudLow);
	replaceMesh(MIC_SHROUD_HI, shroudHi);
	replaceMesh(MIC_BRIDGE, bridge);
	replaceMesh(MIC_HANDLE_BU, handleBridgeUp);
	replaceMesh(MIC_HANDLE_BD, handleBridgeDown);
	replaceMesh(MIC_HANDLE, handle);
	replaceMesh(MIC_HANDLE_TOP, handleTop);

	for (int i = MIC_HEAD; i < PARTS_NUM; i++){
		micParts[i]->Translate(	micParts[i]->getPosition().x,
								micParts[i]->getPosition().y,
								bridge.getPosition().z + bridge.getHeight() + hR);
		recalcMeshVertices((MIC_PART)i, *micParts[i]);
	}
}
Exemplo n.º 7
0
void Microphone::setHandleIndent (float i) {
	float shift = i - hI;
	hI = i;
	Pyramid			handleBridgeUp	(uH * 0.09155f, uR * 0.653f, hI * 1.5f, uR * 0.653f, hI * 1.5f),
					handleBridgeDown(uH * 0.077f,   uR * 0.653f, hI * 1.5f, uR * 0.653f, hI * 1.5f);
	handleBridgeUp.Fly(tH * 0.46f);
	handleBridgeUp.Follow(uR + hI / 2.f);
	handleBridgeDown.Fly(tH * 0.15f);
	handleBridgeDown.Follow(handleBridgeUp.getPosition().x);
	replaceMesh(MIC_HANDLE_BU, handleBridgeUp);
	replaceMesh(MIC_HANDLE_BD, handleBridgeDown);

	for (int i = MIC_HANDLE; i < MIC_HEAD; i++){
		micParts[i]->Translate(	micParts[i]->getPosition().x + shift,
								micParts[i]->getPosition().y,
								micParts[i]->getPosition().z);
		recalcMeshVertices((MIC_PART)i, *micParts[i]);
	}
}
Exemplo n.º 8
0
/**
* Acts as the display function for the window.
*/
static void RenderSceneCB()
{
	vector<glm::vec4> transformedVertices;

	// Clear the color buffer
	colorBuffer.clearColorBuffer();

	static float angle = glm::radians(45.0f);

	angle += glm::radians(1.0f);

	// Set Modeling transformation for the reference plane
	modelingTransformation = glm::translate(glm::vec3(0.0f, -3.0f, 0.0f));
	refPlane.draw();

	// Set modeling transformation for the front left pyramid
	modelingTransformation = glm::translate(glm::vec3(-3.5f, -2.5f, 3.5f));
	pyramid.draw(color(0.0f, 0.0f, 1.0f, 1.0f));

	// Set modeling transformation for the back right pyramid
	modelingTransformation = glm::translate(glm::vec3(3.5f, -2.5f, -3.5f));
	pyramid.draw(color(0.0f, 0.0f, 1.0f, 1.0f));

	// Set modeling transformation for the center pyramid
	modelingTransformation = glm::translate(glm::vec3(0.0f, 0.0f, 0.0f)) * glm::rotate(angle,glm::vec3(0.0f, 1.0f, 0.0f));
	pyramid.draw(color(1.0f, 0.0f, 0.0f, 1.0f));

	// Set modeling transformation for the right hand pyramid
	modelingTransformation = glm::translate(glm::vec3(3.0f, 0.0f, 0.0f)) * glm::rotate(angle, glm::vec3(1.0f, 0.0f, 0.0f));
	sphere.draw( color(1.0f, 1.0f, 0.0f, 1.0f));

	// Set modeling transformation for the left hand pyramid
	modelingTransformation = glm::translate(glm::vec3(-3.0f, 0.0f, 0.0f)) * glm::rotate(angle, glm::vec3(0.0f, 0.0f, 1.0f)) * glm::scale(glm::vec3(2.0f, 2.0f, 2.0f));
	pyramid.draw( color(1.0f, 0.0f, 1.0f, 1.0f));

	// Set modeling transformation for the orbiting pyramid
	modelingTransformation = glm::rotate(angle, glm::vec3(0.0f, 1.0f, 0.0f))* glm::translate(glm::vec3(10.0f, 3.0f, 0.0f)) *glm::rotate(-angle, glm::vec3(1.0f, 0.0f, 0.0f));
	pyramid.draw( color(1.0f, 1.0f, 1.0f, 1.0f));

	// Display the color buffer
	colorBuffer.showColorBuffer();

} // end RenderSceneCB
Exemplo n.º 9
0
int main()
{

  cout << fixed << showpoint << setprecision(2);

  Cylinder one;
  cout << "Enter cylinder height and radius >>> ";
  cin >> one;
  cout << "The cylinder volume is " << one.volume(one) << endl;
  cout << "The cylinder surface area is " << one.surface_area(one) << endl;
  cout << one;

  Sphere two;
  cout << "Enter sphere radius >>> ";
  cin >> two.radius;
  cout << "The sphere volume is " << two.volume(two) << endl;
  cout << "The sphere surface area is " << two.surface_area(two) << endl;
  cout << two.radius << endl;

  Prism three;
  cout << "Enter rectangular prism base length, height, and width >>> ";
  cin >> three;
  cout << "The rectangular prism volume is " << three.volume(three) << endl;
  cout << "The rectangular prism surface area is " << three.surface_area (three) << endl;
  cout << three;

  Cone four;
  cout << "Enter cone height and radius >>> ";
  cin >> four;
  cout << "The cone volume is " << four.volume(four) << endl;
  cout << "The cone surface area is " << four.surface_area(four) << endl;
  cout << four;

  Pyramid five;
  cout << "Enter pyramid base side length and height >>> ";
  cin >> five;
  cout << "The pyramid volume is " << five.volume(five) << endl;
  cout << "The pyramid surface area is " << five.surface_area(five) << endl;
  cout << five;

  return 0;
}
Exemplo n.º 10
0
void TwoBones::SetBoneHierarchy()
{
    // setup the bone model, this case we are using pyramid
    // todo - create a cool Bone Object, ball(drk blue) + pyramid arm (dark yellow)
    Pyramid* pPyramid = new Pyramid();
    pPyramid->loadTexture();
    pPyramid->createVAO();

    // Get the manager
    GraphicsObjectManager *goMgr = GraphicsObjectManager::getInstance();

    // here we insert bones directly into tree - 
    // vs calling goMgr->addObject which inserts every node with root as parent FIXME
    PCSTree* tree = goMgr->getTree();
    PCSNode* root = tree->getRoot();

    // create two bones
    PyramidObject* p0 = new PyramidObject( "name", pPyramid );
    p0->setIndex(0);
    p0->setName("Bone_0");
    tree->insert(p0, root);
    
    p0->setPos( Vect(0.0f, 0.0f, 0.0f) );
    p0->setLightPos( Vect(50.0f, 50.0f, 0.0f) );
    p0->setLightColor( Vect(1.5f, 0.5f, 0.5f) );   // RED
    

    PyramidObject* p1 = new PyramidObject( "name", pPyramid );
    p1->setIndex(1);
    p1->setName("Bone_1");
    tree->insert(p1, p0);

    p1->setPos( Vect(1.0f, 1.0f, 0.0f) );
    p1->setLightPos( Vect(50.0f, 50.0f, 0.0f) );
    p1->setLightColor( Vect(0.5f, 1.5f, 0.5f) );   // Green

    // set the first bone to pass into updateSkeleton in GlobalState.cpp's GameLoop()
    this->SetFirstBone(p0);

    // Debug
    tree->dumpTree();
}
Exemplo n.º 11
0
void smooth_helper(Pyramid& p, smooth_level_fun smooth, const size_t top_level)
{
    using boost::irange;
    using boost::adaptors::reversed;
    using namespace std;

    auto cnt = 0;
    auto v_copy = ImagePyramid{p.get_value2()};
    auto w_copy = LinkPyramid{p.get_links()};

    auto levels = irange(0ul, top_level + 1);

    for (const auto lv : levels | reversed) {
        cout << "Smoothing Level " << lv << " ... ";
        cnt += smooth(v_copy, w_copy, lv);
        cout << endl;
    }
    p.set_result(v_copy.bottom());
    cout << "Done." << endl;
    cout << "Number of Segments: " << cnt << endl;
}
Exemplo n.º 12
0
/**
 * @function main
 */
int main( int argc, char* argv[] ) {

    // Read image
    if( argc < 2 )
    { printf("You moron! I need an image \n"); return -1; }

    // Load image
    cv::Mat img = cv::imread( argv[1], -1 );

    // Create a Pyramid object
    Pyramid pyr;

    // Apply REDUCE 4 times to build the Gaussian Pyramid
   
    GP.resize(4);
    GP[0] = img.clone();
    GP[1] = pyr.Reduce( GP[0] );
    GP[2] = pyr.Reduce( GP[1] );
    GP[3] = pyr.Reduce( GP[2] );     


    // Write images
    imwrite("proj5-1-1-G0.png", GP[0]);    
    imwrite("proj5-1-1-G1.png", GP[1]);    
    imwrite("proj5-1-1-G2.png", GP[2]);    
    imwrite("proj5-1-1-G3.png", GP[3]);  

    // Show results
    cv::namedWindow("G0", CV_WINDOW_NORMAL );
    cv::namedWindow("G1", CV_WINDOW_NORMAL );
    cv::namedWindow("G2", CV_WINDOW_NORMAL );
    cv::namedWindow("G3", CV_WINDOW_NORMAL );     

    imshow( "G0", GP[0] );
    imshow( "G1", GP[1] );
    imshow( "G2", GP[2] );
    imshow( "G3", GP[3] );

    cv::waitKey(0);  
}
void SimpleWaldboost::createPyramids(cv::Size base, cv::Size min, int octaves, int levelsPerOctave)
{
	float scale = pow(2.0f, 1.0f / levelsPerOctave);
	_pyramids.clear();

	bool isLandscape = _image.cols > _image.rows;
	cv::Size newSize;

	for (int i = 0; i < octaves; ++i) 
	{
		cv::Size size = base;
		size.width /= static_cast<float>(i + 1);
		size.height /= static_cast<float>(i + 1);

		float scale = isLandscape ? _image.cols / size.width : _image.rows / size.width;									

		newSize.width = _image.cols / scale;
		newSize.height = _image.rows / scale;		
		
		Pyramid p;		
		for (int j = 0; j < levelsPerOctave; ++j)
		{
			PyramidImage pi;
							
			cv::resize(_image, pi.image, newSize);	
			pi.scale = scale;

			p.push_back(pi);
		
			size.width /= scale;
			size.height /= scale;

			if (size.width <= min.width || size.height <= min.height)
				break;
		}

		_pyramids.push_back(p);
	}
	
}
Exemplo n.º 14
0
Stats<floating_t> stats_downward_links(const Pyramid& p, const Node& node)
{
    using accumulators::extract::sum;
    using accumulators::stat_acc;
    namespace tag = accumulators::tag;
    using accumulators::left;

    auto acc = stat_acc<floating_t>{tag::tail<left>::cache_size = 16};
    for (const auto& desc : common::descs(node)) {
        acc(p.get_links()(node, desc));
    }
    return Stats<floating_t>{"down links", node.level, acc};
}
Exemplo n.º 15
0
/**
* Acts as the display function for the window.
*/
static void RenderSceneCB()
{
	vector<glm::vec4> transformedVertices;

	// Clear the color buffer
	colorBuffer.clearColorBuffer();

	static float angle = glm::radians(45.0f);

	angle += glm::radians(0.1f);

	// Set Modeling transformation for the reference plane
	modelingTransformation = glm::translate(glm::vec3(0.0f, -3.0f, 0.0f));
	gameBoard.draw();




	// Set modeling transformation for the back right pyramid on top of cube
	modelingTransformation = glm::translate(glm::vec3(3.5f, -1.5f, -3.5f));
	pyramid.draw(color(0.502f, 0.0f, 0.502f, 1.0f));

	//cube under pyramid
	modelingTransformation = glm::translate(glm::vec3(3.5f, -2.5f, -3.5f));
	cube.draw(color(0.502f, 0.0f, 0.502f, 1.0f));




	// Set modeling transformation for the center pyramid
	modelingTransformation = glm::translate(glm::vec3(-0.5f, -2.5f, -0.5f));
	cube.draw(color(0.0f, 1.0f, 0.0f, 1.0f));

	// Set modeling transformation for the center pyramid
	modelingTransformation = glm::translate(glm::vec3(0.5f, -2.5f, -0.5f));
	cube.draw(color(1.0f, 1.0f, 0.0f, 1.0f));

	// red cube
	modelingTransformation = glm::translate(glm::vec3(0.0f, -2.5f, 0.5f));
	cube.draw(color(1.0f, 0.0f, 0.0f, 1.0f));

	// Set modeling transformation for the center pyramid
	modelingTransformation = glm::translate(glm::vec3(0.0f, -1.5f, 0.0f))*glm::rotate(4.0f, glm::vec3(0.0f, 1.0f, 0.0f));;
	cube.draw(color(0.0f, 0.0f, 1.0f, 1.0f));

	// Display the color buffer
	colorBuffer.showColorBuffer();

} // end RenderSceneCB
Exemplo n.º 16
0
/*
 * Check for collisions with a pyramid. If we are return true
 * otherwise return false.
 */
bool Cube::checkCollisionPir(Pyramid p)
{
	float r0sqr = getRadius() * getRadius();
	float r1sqr = p.getRadius() * p.getRadius();

	float distX = getCenter().x - p.getCenter().x;
	float distY = getCenter().y - p.getCenter().y;
	float distZ = getCenter().z - p.getCenter().z;

	// Since we already need to square these, we won't need to take the absolute value
	// to accurately compare them to the radii
	distX *= distX;
	distY *= distY;
	distZ *= distZ;

	float sqrDist = (distX+distY+distZ);

	if((r0sqr + r1sqr) > sqrDist )
	{
		return true;
	}
	
	return false;
}
Exemplo n.º 17
0
int WangTilesProcessor::TileMismatch(const TilePack & tiles,
                                     const Pyramid & input)
{
    int result = -1;

    for(int lev = 0; lev < input.NumLevels(); lev++)
    {
        if(TileMismatch(tiles, input[lev]))
        {
            result = lev;
            break;
        }
    }

    return result;
}
Exemplo n.º 18
0
void print_stats(const Pyramid& p, level_t lv)
{
    using namespace stats;
    if (lv > 0) {
        std::cout << std::endl << analyse_weights(p.get_links(), lv);
    }
    std::cout << std::endl << detail::analyse("area", p.get_area()[lv]);
    std::cout << std::endl << detail::analyse("looks", p.get_looks()[lv]);
    std::cout << std::endl << detail::analyse("var", p.get_var()[lv]);

    std::cout << std::endl << detail::analyse("v1_00", p.get_value1()[lv], 0);
    std::cout << std::endl << detail::analyse("v1_11", p.get_value1()[lv], 1);
    std::cout << std::endl << detail::analyse("v1_22", p.get_value1()[lv], 2);

    std::cout << std::endl << detail::analyse("v2_00", p.get_value2()[lv], 0);
    std::cout << std::endl << detail::analyse("v2_11", p.get_value2()[lv], 1);
    std::cout << std::endl << detail::analyse("v2_22", p.get_value2()[lv], 2);

    std::cout << std::endl;
}
Exemplo n.º 19
0
int WangTilesProcessor::BoxSanitize(const TilePack & tiles,
                                    const Pyramid & input,
                                    Pyramid & output,
                                    const int do_corner)
{
    // initialize output size
    output = input;

    // sanitize each level, from high resolution to low resolution
    for(int level = 0; level < input.NumLevels(); level++)
    {
        Array3D<Pixel> & level_now = output[level];
            
        if(level > 0)
        {
            const Array3D<Pixel> & level_up = output[level-1];
        
            // perform initial box filtering + down-sampling from previous level
            for(int row = 0; row < level_now.Size(0); row++)
                for(int col = 0; col < level_now.Size(1); col++)
                    for(int cha = 0; cha < level_now.Size(2); cha++)
                    {
                        Pixel temp = 0;
                    
                        for(int i = 2*row; i <= 2*row+1; i++)
                            for(int j = 2*col; j <= 2*col+1; j++)
                            {
                                const int row_up = i%level_up.Size(0);
                                const int col_up = j%level_up.Size(1);
                                        
                                temp += level_up[row_up][col_up][cha];
                            }

                        level_now[row][col][cha] = temp/4.0;
                    }
        }

        if(!SanitizeEdges(tiles, level_now, level_now)) return 0;
        if(do_corner && !SanitizeCorners(tiles, level_now, level_now)) return 0;
    }
    
    // done
    return 1;
}
Exemplo n.º 20
0
/**
 * @function main
 */
int main( int argc, char* argv[] ) {

    /// Read image
    if( argc < 3 )
    { printf("You moron! I need at least two images \n"); return -1; }

    /// Load images as they are
    cv::Mat L = cv::imread( argv[1], -1 );
    cv::Mat R = cv::imread( argv[2], -1 );
  
    // Have ready my Pyramid  and LK object
    Pyramid pyr;
    LK lk;

    // Hierarchical LK
    int n = 4; // Max level 
    int k;

    // Get the required pyramid levels
    std::vector<cv::Mat> PL(n+1);
    std::vector<cv::Mat> PR(n+1);

    PL[0] = L.clone();
    PR[0] = R.clone();

    for( int i = 1; i <= n; i++ ) {
      PL[i] = pyr.Reduce( PL[i-1] );
      PR[i] = pyr.Reduce( PR[i-1] );
    }

    /// Let's start the real thing
    cv::Mat Lk, Rk;
    cv::Mat U, V;
    cv::Mat Dx, Dy; 
    cv::Mat Wk;
    cv::Mat Wkg, Rkg, Lkg;

    /// 1. Initialize k = n
    k = n;

    while( k >= 0 ) {

      /// 2. Reduce both images to level k
      Lk = PL[k]; 
      Rk = PR[k]; 

      /// 3. If k = n initialize U and K to zeros of the size of Lk 
      if( k == n ) {
          U = cv::Mat::zeros( Lk.size(), CV_32FC1 );
          V = cv::Mat::zeros( Lk.size(), CV_32FC1 );
      }
      /// Else expand the flow field and double it
      else {
          cv::Mat tempU, tempV;
          tempU = pyr.ExpandFloat(U);
          tempV = pyr.ExpandFloat(V);

          U = cv::Mat( tempU.size(), CV_32FC1 );
          V = cv::Mat( tempV.size(), CV_32FC1 );

          for( int j = 0; j < U.rows; j++ )
          { for( int i = 0; i < U.cols; i++ )
            {
               U.at<float>(j,i) = ( 2.0*tempU.at<float>(j,i) );
               V.at<float>(j,i) = ( 2.0*tempV.at<float>(j,i) );
            }
          }
      }

      /// 4. Warp Lk using U and V to form Wk
      Wk = lk.Remap2to1( Rk, U, V );
      char buf[30];
      sprintf( buf, "Wk%d.png", k);
      imwrite( buf, Wk );

      /// 5. Perform LK on Wk and Rk
      cvtColor( Wk, Wkg, CV_BGR2GRAY );
      cvtColor( Lk, Lkg, CV_BGR2GRAY );
      cvtColor( Rk, Rkg, CV_BGR2GRAY );

      //lk.OpticFlowEstimation1( Lkg, Wkg, Dx, Dy, 2.0 );
      //lk.OpticFlowEstimation3( Lkg, Wkg, Dx, Dy, 2.0 );
   
      /// 6. Add these to the original flow
      for( int j = 0; j < U.rows; j++ )
      { for( int i = 0; i < U.cols; i++ )
        {
           U.at<float>(j,i) = U.at<float>(j,i) + Dx.at<float>(j,i);
           V.at<float>(j,i) = V.at<float>(j,i) + Dy.at<float>(j,i);
        }
      }

      cv::Mat temp = lk.Remap2to1( Rk, U, V );
      sprintf( buf, "Wk%dend.png", k);
      imwrite( buf, temp );   

      k = k - 1;
    } // end of while

    cv::Mat mU, mV;
    lk.DrawMotionArrows3( U, V, mU, mV );


    cv::Mat remap;
    remap = lk.Remap2to1( R, U, V );


    cv::Mat remapg;
    cvtColor( remap, remapg, CV_BGR2GRAY );
    cv::Mat diffRemap;
    diffRemap = lk.GetDiff( remapg, L );

    cv::Mat diff21;
    diff21 = lk.GetDiff( L, R );

    /// Write images
    imwrite("proj5-3-1-U.png", mU );    
    imwrite("proj5-3-1-V.png", mV );    
    imwrite("proj5-3-1-remap.png", remap );
    imwrite("proj5-3-1-diffRemap.png", diffRemap );
    //imwrite("proj5-3-1-diff21.png", diff21 );

    // Show results
    cv::namedWindow("U", CV_WINDOW_NORMAL );
    cv::namedWindow("V", CV_WINDOW_NORMAL );
    cv::namedWindow("Remap 2 to 1", CV_WINDOW_NORMAL );
    cv::namedWindow("Diff Image", CV_WINDOW_NORMAL );
    cv::namedWindow("21Diff", CV_WINDOW_NORMAL );

    imshow( "U", mU );
    imshow( "V", mV );

    imshow( "Remap 2 to 1", remap );
    imshow( "Diff Image", diffRemap );
    imshow(  "21Diff", diff21 );


    cv::waitKey(0);
    return 0;

}
Exemplo n.º 21
0
void Microphone::Triangulate() {
	vertices.clear();
	edges.clear();
	polygons.clear();

	ExCone			base(bH, bR, bR, bR * 0.824f, precision);
	Pyramid			buttonL(bH * 0.6f, bW * 0.575f, bW, bW * 0.3f, bW, -bW * 0.1375f),
					buttonR(bH * 0.6f, bW * 0.575f, bW, bW * 0.3f, bW, -bW * 0.1375f);
	
	Cone			shroudLow(uH * 0.21127f, uR, uR, precision),
					bridge   (uH * 0.084537f, uR * 0.66667f, uR * 0.41667f, precision),
					shroudHi (uH - uG - shroudLow.getHeight() - uH * .04f - bridge.getHeight(), uR, uR, precision),
					upright	 (uH - bridge.getHeight(), uR * 0.66667f, uR * 0.66667f, precision);

	Pyramid			handleBridgeUp	(uH * 0.09155f, uR * 0.653f, hI, uR * 0.653f, hI),
					handleBridgeDown(uH * 0.077f,   uR * 0.653f, hI, uR * 0.653f, hI),
					handle			(uH * 0.7598f,  uR * 0.792f, uR * 0.5418f, uR * 0.5418f, uR * 0.5418f, uR * 0.125f),
					handleTop		(uH * 0.05647f, uR * 0.792f, uR * 0.5418f, uR * 0.792f,  uR * 0.5418f,-uR * 0.3542f);

	Hole			head	 (hD,  hR,	 cR, hR, cR, precision),
					headFront(hD / 10.f, hR * 1.075f, cR * 0.9f, hR * 1.075f, cR * 0.9f, precision),
					headBack (hD / 10.f, hR * 1.075f, cR * 0.9f, hR * 1.075f, cR * 0.9f, precision);
	Cone			core	 (hD * 1.43333f,  cR, cR, precision);

	base.Yaw(-(FLOAT)M_PI_2);
	base.Transform();

	buttonL.Translate(-bR * 0.2588f, bR * 0.824f, bH * 1.1f);
	buttonL.Pitch((FLOAT)M_PI);
	buttonL.Transform();

	buttonR.Translate(bR * 0.2588f, bR * 0.824f, bH * 1.1f);
	buttonR.Pitch((FLOAT)M_PI);
	buttonR.Transform();

	upright.Fly(bH);
	upright.Transform();

	shroudLow.Fly(base.getHeight() + uH * .04f);
	shroudLow.Transform();

	shroudHi.Fly(shroudLow.getPosition().z + shroudLow.getHeight() + uG);
	shroudHi.Transform();

	bridge.Fly(shroudHi.getPosition().z + shroudHi.getHeight());
	bridge.Transform();

	handleBridgeUp.Fly(uH * 0.8f);
	handleBridgeUp.Follow(uR + hI / 2);
	handleBridgeUp.Transform();

	handleBridgeDown.Fly(bH + uH * 0.15f);
	handleBridgeDown.Follow(handleBridgeUp.getPosition().x);
	handleBridgeDown.Transform();

	handle.Translate(uR * 1.5f + hI, bR * 0.0059f, uH * .95f);
	handle.Pitch((FLOAT)M_PI);
	handle.Yaw((FLOAT)M_PI_2);
	handle.Transform();

	handleTop.Translate(handle.getPosition().x, handle.getPosition().y, handle.getPosition().z);
	handleTop.Yaw((FLOAT)M_PI_2);
	handleTop.Transform();

	head.Fly(bridge.getPosition().z + bridge.getHeight() + hR);
	head.Strafe(-hD/2);
	head.Pitch((FLOAT)M_PI_2);
	head.Roll((FLOAT)M_PI_2);
	head.Transform();

	headFront.Fly(head.getPosition().z);
	headFront.Strafe(-head.getPosition().y);
	headFront.Pitch((FLOAT)M_PI_2);
	headFront.Roll((FLOAT)M_PI_2);
	headFront.Transform();

	headBack.Translate(head.getPosition());
	headBack.Pitch((FLOAT)M_PI_2);
	headBack.Roll((FLOAT)M_PI_2);
	headBack.Transform();

	core.Fly(head.getPosition().z);
	core.Strafe(-core.getHeight() / 2.1f);
	core.Pitch((FLOAT)M_PI_2);
	core.Roll((FLOAT)M_PI_2);
	core.Transform();

	addMesh(MIC_BASE,		base);
	addMesh(MIC_BUTTON_L,	buttonL);
	addMesh(MIC_BUTTON_R,	buttonR);
	addMesh(MIC_UPRIGHT,	upright);
	addMesh(MIC_SHROUD_LOW,	shroudLow);
	addMesh(MIC_SHROUD_HI,	shroudHi);
	addMesh(MIC_BRIDGE,		bridge);
	addMesh(MIC_HANDLE_BU,	handleBridgeUp);
	addMesh(MIC_HANDLE_BD,	handleBridgeDown);
	addMesh(MIC_HANDLE,		handle);
	addMesh(MIC_HANDLE_TOP,	handleTop);
	addMesh(MIC_HEAD,		head);
	addMesh(MIC_HEAD_FRONT,	headFront);
	addMesh(MIC_HEAD_BACK,	headBack);
	addMesh(MIC_CORE,		core);

	Transform();
	vertices.shrink_to_fit();
	edges.shrink_to_fit();
	polygons.shrink_to_fit();

//	flipNormals(0, polygons.size());
}
Exemplo n.º 22
0
    /**
     * @brief execute
     * @param imgIn
     * @param imgOut
     * @return
     */
    Image *execute(Image *imgIn, Image *imgOut)
    {
        if(imgIn == NULL) {
            return NULL;
        }

        if(!imgIn->isValid()) {
            return NULL;
        }

        if(imgOut == NULL) {
            imgOut = new Image(1, imgIn->width, imgIn->height, imgIn->channels);
        }

        //compute segmentation map
        seg_map = seg.Process(imgIn, seg_map);

        /*	0 ---> Drago et al. 2003
        	1 ---> Reinhard et al. 2002
        	LumZone     = [-2, -1, 0, 1, 2, 3, 4];
        	TMOForZone =  [ 0,  0, 1, 0, 1, 0, 0];	*/

        int count[2];
        count[0] = 0;
        count[1] = 0;

        for(int i = 0; i < seg_map->size(); i++) {
            int indx = int(seg_map->data[i]);

            if((indx == 2) || (indx == 4)) {
                seg_map->data[i] = 1.0f;
                count[1]++;
            } else {
                seg_map->data[i] = 0.0f;
                count[0]++;
            }
        }

#ifdef PIC_DEBUG
        seg_map->Write("weight_map.pfm");
#endif

        //check if we have different zones
        int value = 10;

        if(count[0] > 0 && count[1] > 0) {
            value = 10;
        }

        if(count[0] > 0 && count[1] == 0) {
            value = 0;
        }

        if(count[0] == 0 && count[1] > 0) {
            value = 1;
        }

        switch(value) {
        case 0: {
            fltDragoTMO.Process(Single(imgIn), imgOut);
        }
        break;

        case 1: {
            fltReinhardTMO.Process(Single(imgIn), imgOut);
        }
        break;

        case 10: {
            //Drago TMO
            imgDrago = fltDragoTMO.Process(Single(imgIn), imgDrago);

            if(pyrA == NULL) {
                pyrA = new Pyramid(imgDrago, true);
            } else {
                pyrA->update(imgDrago);
            }

            //Reinhard TMO
            imgReinhard = fltReinhardTMO.Process(Single(imgIn), imgReinhard);

            if(pyrB == NULL) {
                pyrB = new Pyramid(imgReinhard, true);
            } else {
                pyrB->update(imgReinhard);
            }

            //compute blending weight
            if(pyrWeight == NULL) {
                pyrWeight = new Pyramid(seg_map, false);
            } else {
                pyrWeight->update(seg_map);
            }

            //blend
            pyrA->blend(pyrB, pyrWeight);
            pyrA->reconstruct(imgOut);
        }
        break;
        }

        return imgOut;
    }
Exemplo n.º 23
0
Pyramid *Pyramid::create(float length_of_edge)
{
	Pyramid *p = new Pyramid(length_of_edge);
	p->init(length_of_edge);
	return p;
}
Exemplo n.º 24
0
bool InitWindowsApp(HINSTANCE instanceHandle, int show)
{
	//ShowCursor(0);

	// The first task to creating a window is to describe some of its 
	// characteristics by filling out a WNDCLASS structure.
	WNDCLASS wc;
	wc.style         = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc   = WndProc; 
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = instanceHandle;
	wc.hIcon         = LoadIcon(0, IDI_APPLICATION);
	wc.hCursor       = LoadCursor(0, IDC_CROSS);
	wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
	wc.lpszMenuName  = 0;
	wc.lpszClassName = L"BasicWndClass";

	// Next, we register this WNDCLASS instance with Windows so that we can 
	// create a window based on it.
	if(!RegisterClass(&wc)) 
	{
		MessageBox(0, L"RegisterClass FAILED", 0, 0);
		return false;
	}

	// With our WNDCLASS instance registered, we can create a window with the
	// CreateWindow function.  This function returns a handle to the window it
	// creates (an HWND).  If the creation failed, the handle will have the value
	// of zero.  A window handle is a way to refer to the window, which is internally
	// managed by Windows.  Many of the Win32 API functions that operate on windows
	// require an HWND so that they know what window to act on.

	RECT rc;
	rc.left = 0;
	rc.top = 0;
	rc.right = SCREEN_WIDTH;
	rc.bottom = SCREEN_HEIGHT;
	AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, false);

	g_Hwnd = CreateWindow(
		L"BasicWndClass",	 // Registered WNDCLASS instance to use.
		L"Gruppuppgift",	// window title
		WS_OVERLAPPEDWINDOW, // style flags
		CW_USEDEFAULT,		 // x-coordinate
		CW_USEDEFAULT,       // y-coordinate
		rc.right - rc.left,        // width
		rc.bottom - rc.top,       // height
		0,               // parent window
		0,               // menu handle
		instanceHandle,      // app instance
		0);              // extra creation parameters

	if(g_Hwnd == 0)
	{
		MessageBox(0, L"CreateWindow FAILED", 0, 0);
		return false;
	}

	// Even though we just created a window, it is not initially shown.  
	// Therefore, the final step is to show and update the window we just
	// created, which can be done with the following two function calls.
	// Observe that we pass the handle to the window we want to show and
	// update so that these functions know which window to show and update.

	ShowWindow(g_Hwnd, show);
	UpdateWindow(g_Hwnd);

	//________________________________

	// Fill out a DXGI_SWAP_CHAIN_DESC to describe our swap chain.
	DXGI_SWAP_CHAIN_DESC sd;
	sd.BufferDesc.Width  = SCREEN_WIDTH;
	sd.BufferDesc.Height = SCREEN_HEIGHT;
	sd.BufferDesc.RefreshRate.Numerator = 60;
	sd.BufferDesc.RefreshRate.Denominator = 1;
	sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;

	// No multisampling.
	sd.SampleDesc.Count   = 1;
	sd.SampleDesc.Quality = 0;

	sd.BufferUsage  = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	sd.BufferCount  = 1;
	sd.OutputWindow = g_Hwnd;
	sd.Windowed     = true;
	sd.SwapEffect   = DXGI_SWAP_EFFECT_DISCARD;
	sd.Flags        = 0;

	D3D10CreateDeviceAndSwapChain(
		0,                 //default adapter
		D3D10_DRIVER_TYPE_HARDWARE,
		0,                 // no software device
		0, 
		D3D10_SDK_VERSION,
		&sd,
		&mSwapChain,
		&md3dDevice);

	ID3D10Texture2D* backBuffer;
	mSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&backBuffer);
	md3dDevice->CreateRenderTargetView(backBuffer, 0, &mRenderTargetView);
	backBuffer->Release();
	backBuffer = 0;

	
	// Create depth stencil texture
	D3D10_TEXTURE2D_DESC descDepth;
	ZeroMemory( &descDepth, sizeof(descDepth) );
	descDepth.Width = SCREEN_WIDTH;
	descDepth.Height = SCREEN_HEIGHT;
	descDepth.MipLevels = 1;
	descDepth.ArraySize = 1;
	descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
	descDepth.SampleDesc.Count = 1;
	descDepth.SampleDesc.Quality = 0;
	descDepth.Usage = D3D10_USAGE_DEFAULT;
	descDepth.BindFlags = D3D10_BIND_DEPTH_STENCIL;
	descDepth.CPUAccessFlags = 0;
	descDepth.MiscFlags = 0;
	md3dDevice->CreateTexture2D( &descDepth, NULL, &mDepthStencil );

	// Create the depth stencil view
	D3D10_DEPTH_STENCIL_VIEW_DESC descDSV;
	ZeroMemory( &descDSV, sizeof(descDSV) );
	descDSV.Format = descDepth.Format;
	descDSV.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
	descDSV.Texture2D.MipSlice = 0;

	// Bind the render target view and depth/stencil view to the pipeline.
	md3dDevice->CreateDepthStencilView( mDepthStencil, &descDSV, &mDepthStencilView );
	md3dDevice->OMSetRenderTargets( 1, &mRenderTargetView, mDepthStencilView );

	// Set the viewport transform.
	vp.TopLeftX = 0;
	vp.TopLeftY = 0;
	vp.Width    = SCREEN_WIDTH;
	vp.Height   = SCREEN_HEIGHT;
	vp.MinDepth = 0.0f;
	vp.MaxDepth = 1.0f;
	md3dDevice->RSSetViewports(1, &vp);
	//________________________________

	Effects::InitAll(md3dDevice);
	fxU.init(md3dDevice, Effects::MeshFX);

	Terrain::InitInfo tii;
	tii.CellSpacing = 1.0f;
	tii.HeightmapFilename = L"flat513.raw";
	tii.HeightOffset = -30.0f;
	tii.HeightScale = 0.2f;
	tii.NumCols = 513;
	tii.NumRows = 513;
	land.init(md3dDevice, tii);
	//mTerrain.init(md3dDevice, (std::string)"Textures/Terrain/HeightMap.raw", 0.35f, -50.0f, 0.1f, 512, 512);

	//Cube c;
	//c.init(md3dDevice, D3DXVECTOR3(2.0f, 2.0f, 2.0f), D3DXVECTOR3(-16.0f, land.getHeight(-16.0f, -16.0f)+1.0f, -16.0f));
	//mCubes.push_back(c);
	//nr.push_back(0);

	nrOfTowers.push_back(0);
	
	mCubes.resize(10);
	for(int i = 0; i < mCubes.size();i++)
	{
		mCubes[i].init(i, md3dDevice, D3DXVECTOR3(5.0f,5.0f,5.0f), D3DXVECTOR3(0.0f, land.getHeight(0.0f,0.0f), 0.0f), (i*0.50f+0.50f));
		nr.push_back(0);
	}
	pWave = new wave(1, 20, md3dDevice, &land);
	pWave->initMonsters();
	
	mPyramid.init(md3dDevice, D3DXVECTOR3(2.0f, 2.0f, 2.0f), D3DXVECTOR3(-16.0f, land.getHeight(-16.0f, -16.0f)+5.0f, -16.0f));
	mCylinder.init(md3dDevice, 1.0f, D3DXVECTOR3(-2.0f, land.getHeight(-2.0f, -8.0f)+1.0f, -8.0f));

	//GetCamera().setPosY(land.getHeight(GetCamera().getPos().x, GetCamera().getPos().z));
	GetCamera().setLens(0.30f*pi, (float)SCREEN_WIDTH/SCREEN_HEIGHT, 1.0f, 1000.0f);

	fire.init(md3dDevice, Effects::FireFX, L"Textures/Particle/flare0.dds", 500);
	fire.setEmitPos(D3DXVECTOR3(-2.0f, land.getHeight(-5.0f, 2.0f)+2.5f, -8.0f));

	rain.init(md3dDevice, Effects::RainFX, L"Textures/Particle/raindrop.gif", 1000);

	sky.init(md3dDevice, L"Textures/Terrain/grassenvmap1024.dds", 5000.0f);
	
	//Trees
	D3DXVECTOR3 treeCenters[6];

	float x = -20.0f;
	float z = 20.0f;
	treeCenters[0] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z);

	x = -23.0f;
	z = 16.0f;
	treeCenters[1] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z);

	x = -3.0f;
	z = 18.0f;
	treeCenters[2] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z);

	x = 22.0f;
	z = 13.0f;
	treeCenters[3] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z);

	x = 17.0f;
	z = -23.0f;
	treeCenters[4] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z);

	x = 22.0f;
	z = -20.0f;
	treeCenters[5] = D3DXVECTOR3(x,land.getHeight(x,z) + 10.0f,z);
	mTrees.init(md3dDevice, treeCenters, 6, L"Textures/Wood/tree3.dds");

	//QuadTree
	qtc.init(md3dDevice, &land, GetCamera().proj(), GetCamera().view());

	//init GUI
	gui.Init(md3dDevice,SCREEN_WIDTH,SCREEN_HEIGHT);
	//set gui callback
	gui.SetCallback(OnGUIEvent);
	//adding a button
	gui.AddButton(PLACE_TOWER,L"test.png",10,10,100,100);

	GetTowerScript().Init("tower");

	return true;
}
Exemplo n.º 25
0
void Render()
{
	md3dDevice->ClearRenderTargetView(mRenderTargetView, mClearColor);
	md3dDevice->ClearDepthStencilView(mDepthStencilView, D3D10_CLEAR_DEPTH|D3D10_CLEAR_STENCIL, 1.0f, 0);
	md3dDevice->OMSetDepthStencilState(0, 0);

	md3dDevice->OMSetBlendState(0, blendFactor, 0xffffffff);

	//draw Trees
	mTrees.draw(GetCamera().getPos(), GetCamera().view()*GetCamera().proj());

	D3D10_TECHNIQUE_DESC techDesc;
	fxU.setRenderUtil(techDesc);

	for(UINT p = 0; p < techDesc.Passes; ++p)
	{
		//draw Cube
		pWave->render(fxU,p);

		//draw Cube "Tower"
		for (UINT i=0; i < mTowers.size(); ++i)
		{
			fxU.setMfx(GetCamera().wvp(mTowers.at(i).getWorld()), mTowers.at(i).getWorld(), 1, nrOfTowers[i]);
			fxU.ApplyPassByIndex(p);
			mTowers.at(i).Draw();
		}

		//draw Pyramid
		fxU.setMfx(GetCamera().wvp(mPyramid.getWorld()), mPyramid.getWorld(), 2, 3);
		fxU.ApplyPassByIndex(p);
		mPyramid.Draw();

		//draw Cylinder
		fxU.setMfx(GetCamera().wvp(mCylinder.getWorld()), mCylinder.getWorld(), 3, 6);
		fxU.ApplyPassByIndex(p);
		mCylinder.Draw();

		//draw Terrain
		//fxU.setMfx(GetCamera().wvp(mTerrain.getWorld()), mTerrain.getWorld(), 0, 9);
		//fxU.ApplyPassByIndex(p);
		//mTerrain.Draw();

		fxU.setMfx(GetCamera().wvp(land.getWorld()), land.getWorld(), 0, 9);
		fxU.ApplyPassByIndex(p);
		land.draw();
	}

	//draw gui
	gui.Render();

	//draw grid
	qtc.draw(GetCamera().view(), GetCamera().proj(), grid);

	//draw Sky
	sky.draw(GetCamera().view(), GetCamera().proj(), GetCamera().getPos(), mLight.lightType);

	//draw Fire
	fire.draw(GetCamera().view(), GetCamera().proj());
	
	md3dDevice->OMSetBlendState(0, blendFactor, 0xffffffff);
	
	//draw Rain
	rain.draw(GetCamera().view(), GetCamera().proj());
	
	mSwapChain->Present(0, 0);
}
Exemplo n.º 26
0
/**
 * @brief ExposureFusion
 * @param imgIn
 * @param wC
 * @param wE
 * @param wS
 * @param imgOut
 * @return
 */
Image *ExposureFusion(ImageVec imgIn, float wC = 1.0f, float wE = 1.0f,
                      float wS = 1.0f, Image *imgOut = NULL)
{
    int n = imgIn.size();

    if(n < 2) {
        return imgOut;
    }

    //Computing weights values
    int channels = imgIn[0]->channels;
    int width = imgIn[0]->width;
    int height = imgIn[0]->height;

    Image *lum     = new Image(1, width, height, 1);
    Image *weights = new Image(1, width, height, 1);
    Image *acc     = new Image(1, width, height, 1);

    acc->SetZero();

    FilterLuminance flt_lum;
    FilterExposureFusionWeights flt_weights(wC, wE, wS);

    for(int j = 0; j < n; j++) {
        #ifdef PIC_DEBUG
            printf("Processing image %d\n", j);
        #endif

        lum = flt_lum.ProcessP(Single(imgIn[j]), lum);

        weights = flt_weights.ProcessP(Double(lum, imgIn[j]), weights);

        *acc += *weights;
    }

    for(int i=0; i<acc->size(); i++) {
        acc->data[i] = acc->data[i] > 0.0f ? acc->data[i] : 1.0f;
    }

    //Accumulation Pyramid
    #ifdef PIC_DEBUG
        printf("Blending...");
    #endif

    Pyramid *pW   = new Pyramid(width, height, 1, false);
    Pyramid *pI   = new Pyramid(width, height, channels, true);
    Pyramid *pOut = new Pyramid(width, height, channels, true);

    pOut->SetValue(0.0f);

    for(int j = 0; j < n; j++) {
        lum = flt_lum.ProcessP(Single(imgIn[j]), lum);
        weights = flt_weights.ProcessP(Double(lum, imgIn[j]), weights);

        //normalization
        *weights /= *acc;

        pW->Update(weights);
        pI->Update(imgIn[j]);

        pI->Mul(pW);

        pOut->Add(pI);
    }

    #ifdef PIC_DEBUG
        printf(" ok\n");
    #endif

    //final result
    imgOut = pOut->Reconstruct(imgOut);

    #pragma omp parallel for
    for(int i = 0; i < imgOut->size(); i++) {
        imgOut->data[i] = MAX(imgOut->data[i], 0.0f);
    }

    //free the memory
    delete pW;
    delete pOut;
    delete pI;

    delete acc;
    delete weights;
    delete lum;

    return imgOut;
}