bool QCamFindShift_barycentre::registerFirstFrame() {
   average_=0;
   maximum_=0;
   int i=cam().size().height()*cam().size().width();
   const unsigned char * img=cam().yuvFrame().Y();
   while (i-->0) {
      unsigned char val=img[i];
      if (val>maximum_) maximum_=val;
      average_+=val;
   }
   average_/=cam().size().height()*cam().size().width();
   return findBarycentre(lastBarycentre_);
}
int main(int argc, char** argv) {

  video_resource cam(0);
  calibrationParameters par = calibrateCamera(10, 7, 5 , cam);
  par.saveToFile("calibration.xml");
  return 0;
}
void eDeferredRenderer::_renderLightDistance(const eScene &scene, const eLight &light)
{
    const eVector3 &lightPos = light.getPosition();

    eRenderState &rs = eGfx->freshRenderState();
    rs.colorWrite = eFALSE;
    rs.vs = m_vsDistance;
    rs.ps = m_psDistance;
    rs.targets[0] = nullptr;
    rs.depthTarget = m_texDistMap;

    eGfx->clear(eCM_DEPTH, eCOL_WHITE);

    eCamera cam(90.0f, 1.0f, 0.1f, light.getRange());
    eMatrix4x4 cubeMtx, viewMtx;
    static eRenderJobQueue jobs; // static to reduce memory allocations

    for (eU32 i=0; i<eCMF_COUNT; i++)
    {
        if (light.getCastsShadows((eCubeMapFace)i))
        {
            rs.viewport.set(i*m_shadowSize, 0, (i+1)*m_shadowSize, m_shadowSize);

            cubeMtx.cubemap(i);
            viewMtx.identity();
            viewMtx.translate(-lightPos);
            viewMtx *= cubeMtx;

            cam.setViewMatrix(viewMtx);
            scene.getRenderJobs(cam, jobs);
            jobs.render(cam, eRJW_RENDER_ALL & ~eRJW_SHADOWS_OFF & ~eRJW_ALPHA_ON, eRJF_MATERIALS_OFF);
        }
    }
}
Esempio n. 4
0
int main(int argc, char **argv) {
    bool use_file = false;
    std::string flag;
    std::string filename;
    int imgSize = atoi(argv[1]);
    if (argc == 4) {
	flag = std::string(argv[2]);
	if (flag != "-f") {
	    std::cout << "Usage: " << argv[0] << " [-f filename]" << std::endl;
	    return 1;
	}
	filename = std::string(argv[3]);
	use_file = true;
    }
    Scene scene;
    Camera cam(Vector3D(-1.5, 1, 3), Vector3D(-0.3, 0.5, 0), Vector3D(0, 1, 0));
    SceneReader reader;
    if (use_file) {
	std::ifstream f(filename.c_str());
	reader.readScene(f, cam, scene);
    }
    else
	reader.readScene(std::cin, cam, scene);
    scene.render(cam, imgSize, std::cout);
    return 0;
}
Esempio n. 5
0
PAIS::Camera FileLoader::loadMvsCamera(ifstream &file) {
	int fileNameLength;
	char *fileName;
	Vec3d center;
	Vec2d focal;
	Vec4d quaternion;
	Vec2d principle;
	double radialDistortion;

	// read image file name length
	file.read( (char*) &fileNameLength, sizeof(int) );
	// read image file name
	fileName = new char [fileNameLength+1];
	file.read(fileName, fileNameLength);
	fileName[fileNameLength] = '\0';
	// read camera center
	loadMvsVec(file, center);
	// read camera focal length
	loadMvsVec(file, focal);
	// read camera principle point
	loadMvsVec(file, principle);
	// read rotation quaternion
	loadMvsVec(file, quaternion);
	// read radial distortion
	file.read((char*) &radialDistortion, sizeof(double));

	Camera cam(fileName, focal, principle, quaternion, center, radialDistortion);

	delete [] fileName;

	return cam;
}
BOOL LLToolCompGun::handleScrollWheel(S32 x, S32 y, S32 clicks)
{
	if (gViewerWindow->getRightMouseDown())
	{
		LLViewerCamera& cam(LLViewerCamera::instance());
		mStartFOV = cam.getDefaultFOV();

		gSavedSettings.setF32(
			"ExodusAlternativeFOV",
			mTargetFOV = clicks > 0 ?
				llclamp(mTargetFOV += (0.05f * clicks), 0.1f, 3.0f) :
				llclamp(mTargetFOV -= (0.05f * -clicks), 0.1f, 3.0f)
		);

		if (gSavedSettings.getBOOL("LiruMouselookInstantZoom"))
			cam.setDefaultFOV(mTargetFOV);
		else
			mTimerFOV.start();
		cam.mSavedFOVLoaded = false;
	}
	else if (clicks > 0)
	{
		gAgentCamera.changeCameraToDefault();
	}
	return TRUE;
}
Esempio n. 7
0
void fsExperiments::draw()
{
	gl::clear( mBackground );

	CameraPersp cam( getWindowWidth(), getWindowHeight(), 60.0f );
	cam.setPerspective( 60, getWindowAspectRatio(), 1, 5000 );
	cam.lookAt( Vec3f( 0, 0, mEyeDistance ), Vec3f::zero(), Vec3f( 0, -1, 0 ) );
	gl::setMatrices( cam );

	gl::setViewport( getWindowBounds() );

	gl::enableDepthRead();
	gl::enableDepthWrite();

	GlobalData& data = GlobalData::get();

	gl::pushModelView();
	gl::rotate( mArcball.getQuat() );
	gl::rotate( data.mHeadRotation );

	mEffects[ mCurrentEffect ]->draw();

	gl::popModelView();

	params::PInterfaceGl::draw();
}
Esempio n. 8
0
  void keyboardFunc(unsigned char k, int, int)
  {
    switch (k)
    {
    case ' ' : {
      g_pause = !g_pause;
      break;
    }
    case 'c' : {
      AffineSpace3f cam(g_camSpace.l,g_camSpace.p);
      std::cout << "-vp " << g_camPos.x    << " " << g_camPos.y    << " " << g_camPos.z    << " " << std::endl
                << "-vi " << g_camLookAt.x << " " << g_camLookAt.y << " " << g_camLookAt.z << " " << std::endl
                << "-vu " << g_camUp.x     << " " << g_camUp.y     << " " << g_camUp.z     << " " << std::endl;
      break;
    }
    case 'd' : {
      g_demo_t0 = getSeconds();
      g_demo_camSpace = AffineSpace3f::lookAtPoint(g_initial_camPos, g_initial_camLookAt, g_initial_camUp);
      g_demo = !g_demo;
      break;
    }
    case 'f' : glutFullScreen(); break;
    case 'r' : g_refine = !g_refine; break;
    case 't' : g_regression = !g_regression; break;
    case 'l' : g_camRadius = max(0.0f, g_camRadius-1); break;
    case 'L' : g_camRadius += 1; break;
    case '\033': case 'q': case 'Q':
      clearGlobalObjects();
      glutDestroyWindow(g_window);
      exit(0);
      break;
    }

    g_resetAccumulation = true;
  }
Esempio n. 9
0
MVS_NAMESPACE_BEGIN

SingleView::SingleView(mve::View::Ptr _view)
    :
    view(_view)
{
    if ((view.get() == NULL) || (!view->is_camera_valid()))
        throw std::invalid_argument("NULL view");
    viewID = view->get_id();

    mve::MVEFileProxy const* proxy = 0;
    proxy = view->get_proxy("tonemapped");
    if (proxy == 0)
        proxy = view->get_proxy("undistorted");
    if (proxy == 0)
        throw std::invalid_argument("No color image found");

    mve::CameraInfo cam(view->get_camera());
    cam.fill_camera_pos(*this->camPos);
    cam.fill_world_to_cam(*this->worldToCam);

    this->width = proxy->width;
    this->height = proxy->height;

    // compute projection matrix
    cam.fill_calibration(*this->proj, width, height);
    cam.fill_inverse_calibration(*this->invproj, width, height);
}
Esempio n. 10
0
void QCamSelection::camConnected() {
   widget_->firtsFrameReceived_=false;
   widget_->resize(cam().size());
   widget_->updateGeometry();
   mainWidget_->adjustSize();
   setWindowTitle();
}
Esempio n. 11
0
int
main()
{
  vpSimulator simu ;

  // Internal view initialization : view from the robot camera
  simu.initInternalViewer(480, 360) ;
  // External view initialization : view from an external camera
  simu.initExternalViewer(300, 300) ; 

  // Inernal camera paramters initialization
  vpCameraParameters cam(800,800,240,180) ;
  simu.setInternalCameraParameters(cam) ;

  vpTime::wait(500) ;
  // Load the scene
  std::cout << "Load : ./4Points.iv" << std::endl
            << "This file should be in the working directory" << std::endl;

  simu.load("./4points.iv") ;

  // Run the main loop
  simu.initApplication(&mainLoop) ;
  // Run the simulator
  simu.mainLoop() ;
}
Esempio n. 12
0
  bool VertexCam::read(std::istream& is)
  {
    // first the position and orientation (vector3 and quaternion)
    Vector3d t;
    for (int i=0; i<3; i++){
      is >> t[i];
    }
    Vector4d rc;
    for (int i=0; i<4; i++) {
      is >> rc[i];
    }
    Quaterniond r;
    r.coeffs() = rc;
    r.normalize();


    // form the camera object
    SBACam cam(r,t);

    // now fx, fy, cx, cy, baseline
    double fx, fy, cx, cy, tx;

    // try to read one value
    is >>  fx;
    if (is.good()) {
      is >>  fy >> cx >> cy >> tx;
      cam.setKcam(fx,fy,cx,cy,tx);
    } else{
Esempio n. 13
0
int main(int argc, char *argv[]){
  int w=1024, h=768, samps = argc==2 ? atoi(argv[1])/4 : 1; // # samples
  Ray cam(Vec(50,52,295.6), Vec(0,-0.042612,-1).norm()); // cam pos, dir
  Vec cx=Vec(w*.5135/h), cy=(cx%cam.d).norm()*.5135, r, *c=new Vec[w*h];
#pragma omp parallel for schedule(dynamic, 1) private(r)       // OpenMP
  for (int y=0; y<h; y++){                       // Loop over image rows
    // *** Commented out for Visual Studio, fprintf is not thread-safe
    //fprintf(stderr,"\rRendering (%d spp) %5.2f%%",samps*4,100.*y/(h-1));
    unsigned short Xi[3]={0,0,y*y*y}; // *** Moved outside for VS2012
    for (unsigned short x=0; x<w; x++)   // Loop cols
      for (int sy=0, i=(h-y-1)*w+x; sy<2; sy++)     // 2x2 subpixel rows
        for (int sx=0; sx<2; sx++, r=Vec()){        // 2x2 subpixel cols
          for (int s=0; s<samps; s++){
            double r1=2*erand48(Xi), dx=r1<1 ? sqrt(r1)-1: 1-sqrt(2-r1);
            double r2=2*erand48(Xi), dy=r2<1 ? sqrt(r2)-1: 1-sqrt(2-r2);
            Vec d = cx*( ( (sx+.5 + dx)/2 + x)/w - .5) +
                    cy*( ( (sy+.5 + dy)/2 + y)/h - .5) + cam.d;
            r = r + radiance(Ray(cam.o+d*140,d.norm()),0,Xi)*(1./samps);
          } // Camera rays are pushed ^^^^^ forward to start in interior
          c[i] = c[i] + Vec(clamp(r.x),clamp(r.y),clamp(r.z))*.25;
        }
  }
  FILE *f = fopen("image.ppm", "w");         // Write image to PPM file.
  fprintf(f, "P3\n%d %d\n%d\n", w, h, 255);
  for (int i=0; i<w*h; i++)
    fprintf(f,"%d %d %d ", toInt(c[i].x), toInt(c[i].y), toInt(c[i].z));
}
int main(int argc, char **argv){
	Camera cam(0);
	Screen screen;
	BeagleTracker tracker;
	Mat img;
	Rect2d bounderies = Rect2d(100, 100, 50, 50);
	char c=0;
	bool tracking = false;
	bool initialized = false;
	int skipFrames = 0;
	while(c!=27){
		img = cam.getImage();
		if(c == 'p'){
			tracking = !tracking;
		}
		if(tracking) {
			if(!initialized){
				tracker.initialTraining(img, bounderies);
				initialized = !initialized;
			}else if(skipFrames == 0){
				tracker.update(img, bounderies);
			}
		}
		skipFrames = (skipFrames+1)%12;
		screen.drawRectangle(img, bounderies);
		screen.putImage(img);
		c = waitKey(10);
	}
}
Esempio n. 15
0
int main(int argc, char* argv[])
{
    RoboCam cam(VIDEO_WIDTH, VIDEO_HEIGHT, TRUE);
    int x, y ,size, key;
    int frames = 0;
    
    uint64_t start, end;
    
    start = getUsecTime();
    
    while (1) {
        if ( cam.getObjectPosition( 100, &x, &y, &size, &key ) ) {
            printf ( "S.%04d X.%04d Y.%04d\n", size, x, y);
        }
        frames++;
        if ( key == 27 ) {
            break;
        }
    }
    
    end = getUsecTime();
    
    printf("FPS: %2.3f\n", ((float)frames/(float)((end-start)/1000000)));
    
    return 0;
}
Esempio n. 16
0
void display( void )
{
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	glDepthMask( GL_TRUE );

	glUseProgram( glutPro );
	glUniformMatrix4fv(glGetUniformLocation( glutPro, "Projection" ), 1, GL_TRUE, projmat);  //pass to shader
	glUniformMatrix4fv(glGetUniformLocation( glutPro, "ModelView" ), 1, GL_TRUE, modelViewStack.top());

	glUseProgram( arrayPro );
	glUniformMatrix4fv(glGetUniformLocation( arrayPro, "Projection" ), 1, GL_TRUE, projmat);  //pass to shader
	glUniformMatrix4fv(glGetUniformLocation( arrayPro, "ModelView" ), 1, GL_TRUE, modelViewStack.top());

	glUseProgram( skyPro );
	glUniformMatrix4fv(glGetUniformLocation( skyPro, "Projection" ), 1, GL_TRUE, projmat);  //pass to shader
	glUniformMatrix4fv(glGetUniformLocation( skyPro, "ModelView" ), 1, GL_TRUE, modelViewStack.top());

	glUseProgram( cubeMapPro );
	glUniformMatrix4fv(glGetUniformLocation( cubeMapPro, "Projection" ), 1, GL_TRUE, projmat);  //pass to shader
	glUniformMatrix4fv(glGetUniformLocation( cubeMapPro, "ModelView" ), 1, GL_TRUE, modelViewStack.top());

	glUseProgram( carPro );
	glUniformMatrix4fv(glGetUniformLocation( carPro, "Projection" ), 1, GL_TRUE, projmat);  //pass to shader
	glUniformMatrix4fv(glGetUniformLocation( carPro, "ModelView" ), 1, GL_TRUE, modelViewStack.top());

	glPolygonMode(GL_FRONT, GL_FILL);
	
	cam();
	traverse( &nodes[Sky] );  //begin traverse the tree
	glutSwapBuffers();
}
/*----------------------------------------------------------------------------
 Captures an image from the webcam - gets raw image data + dimensions
----------------------------------------------------------------------------*/
void get_cam_img( void *&raw_data, int &width, int &height )
{
    VideoCapture cam( 0 );  /* OpenCV Video Capture         */
    Mat frame;              /* image captured from webcam   */
    Mat grayscale;          /* image converted to grayscale */

    /* get dimensions */
    width = cam.get( CV_CAP_PROP_FRAME_WIDTH );
    height = cam.get( CV_CAP_PROP_FRAME_HEIGHT );

    /* check if we could get a capture */
    if( !cam.read( frame ) )
    {
        dbg_msg( "Could not read from webcam" );
        raw_data = NULL;
        return;
    }

    /* convert to greysale */
    cvtColor( frame, grayscale, CV_BGR2GRAY );

    /* get the raw image data */
    raw_data = malloc( sizeof( char ) * grayscale.rows * grayscale.cols );
    memcpy( raw_data, grayscale.data, sizeof( char ) * grayscale.rows * grayscale.cols);
    cam.release();
}
int CameraHardwareStub::pictureThread()
{
    if (mMsgEnabled & CAMERA_MSG_SHUTTER)
        mNotifyCb(CAMERA_MSG_SHUTTER, 0, 0, mCallbackCookie);

    if (mMsgEnabled & CAMERA_MSG_RAW_IMAGE) {
        //FIXME: use a canned YUV image!
        // In the meantime just make another fake camera picture.
        int w, h;
        mParameters.getPictureSize(&w, &h);
        sp<MemoryBase> mem = new MemoryBase(mRawHeap, 0, w * h * 3 / 2);
        FakeCamera cam(w, h);
        cam.getNextFrameAsYuv420((uint8_t *)mRawHeap->base());
        mDataCb(CAMERA_MSG_RAW_IMAGE, mem, mCallbackCookie);
    }

    if (mMsgEnabled & CAMERA_MSG_COMPRESSED_IMAGE) {
        sp<MemoryHeapBase> heap = new MemoryHeapBase(kCannedJpegSize);
        sp<MemoryBase> mem = new MemoryBase(heap, 0, kCannedJpegSize);
        memcpy(heap->base(), kCannedJpeg, kCannedJpegSize);
        #error aa
        LOGD("%d: %s() mem=%x, cook=%x", __LINE__, __FUNCTION__, (unsigned int)(void *)mem, mCallbackCookie);
        mDataCb(CAMERA_MSG_COMPRESSED_IMAGE, mem, mCallbackCookie);
    }
    return NO_ERROR;
}
Esempio n. 19
0
void IndexMap::predictIndices(const Eigen::Matrix4f & pose,
                              const int & time,
                              const std::pair<GLuint, GLuint> & model,
                              const float depthCutoff,
                              const int timeDelta)
{
    indexFrameBuffer.Bind();

    glPushAttrib(GL_VIEWPORT_BIT);

    glViewport(0, 0, indexRenderBuffer.width, indexRenderBuffer.height);

    glClearColor(0, 0, 0, 0);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    indexProgram->Bind();

    Eigen::Matrix4f t_inv = pose.inverse();

    Eigen::Vector4f cam(Intrinsics::getInstance().cx() * IndexMap::FACTOR,
                  Intrinsics::getInstance().cy() * IndexMap::FACTOR,
                  Intrinsics::getInstance().fx() * IndexMap::FACTOR,
                  Intrinsics::getInstance().fy() * IndexMap::FACTOR);

    indexProgram->setUniform(Uniform("t_inv", t_inv));
    indexProgram->setUniform(Uniform("cam", cam));
    indexProgram->setUniform(Uniform("maxDepth", depthCutoff));
    indexProgram->setUniform(Uniform("cols", (float)Resolution::getInstance().cols() * IndexMap::FACTOR));
    indexProgram->setUniform(Uniform("rows", (float)Resolution::getInstance().rows() * IndexMap::FACTOR));
    indexProgram->setUniform(Uniform("time", time));
    indexProgram->setUniform(Uniform("timeDelta", timeDelta));

    glBindBuffer(GL_ARRAY_BUFFER, model.first);

    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, Vertex::SIZE, 0);

    glEnableVertexAttribArray(1);
    glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, Vertex::SIZE, reinterpret_cast<GLvoid*>(sizeof(Eigen::Vector4f)));

    glEnableVertexAttribArray(2);
    glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, Vertex::SIZE, reinterpret_cast<GLvoid*>(sizeof(Eigen::Vector4f) * 2));

    glDrawTransformFeedback(GL_POINTS, model.second);

    glDisableVertexAttribArray(0);
    glDisableVertexAttribArray(1);
    glDisableVertexAttribArray(2);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    indexFrameBuffer.Unbind();

    indexProgram->Unbind();

    glPopAttrib();

    glFinish();
}
Esempio n. 20
0
void QCamSelection::setWindowTitle() {
   QString labelPrefix;
   labelPrefix="Focus ";

   if (isConnected() && mainWidget_) {
      mainWidget_->setWindowTitle(labelPrefix+cam().label());
   }
}
Esempio n. 21
0
//--------------------------------------------------------------
void Input::selectWebCam() {
  input = nullptr;
  enableClient = false;
  unique_ptr<ofVideoGrabber> cam(new ofVideoGrabber);
  cam->setup(640, 480);
  source = move(cam);
  isSetup = false;
}
Esempio n. 22
0
::Ice::DispatchStatus
Client::CClient::___cam(::IceInternal::Incoming& __inS, const ::Ice::Current& __current)
{
    __checkMode(::Ice::Normal, __current.mode);
    ::IceInternal::BasicStream* __os = __inS.os();
    ::Client::CCamPrx __ret = cam(__current);
    __os->write(::Ice::ObjectPrx(::IceInternal::upCast(__ret.get())));
    return ::Ice::DispatchOK;
}
/** Main entry point */
int main(int argc, char **argv) {
	int height, width, input;
	std::string dev, frame_id, cinfo_url;
	sensor_msgs::Image image;
	sensor_msgs::CameraInfo cam_info;

	ros::init(argc, argv, "camerav4l2_node");
	ros::NodeHandle node;
	ros::NodeHandle nh("~");

	CameraInfoManager cinfo(nh);

	image_transport::ImageTransport it(nh);
	image_transport::CameraPublisher image_pub = it.advertiseCamera(
			"image_raw", 1);

	nh.param<int>("width", width, 640);
	nh.param<int>("height", height, 480);
	nh.param<int>("input", input, 0);
	nh.param<std::string>("device", dev, "/dev/video0");
  nh.param<std::string>("frame_id", frame_id, "camera");
  nh.param<std::string>("camera_info_url", cinfo_url, "file:///tmp/calibration_camera.yaml");

  cinfo.loadCameraInfo(cinfo_url);

	ROS_INFO("Opening device : %s", dev.c_str());
	Camera cam(dev.c_str(), width, height);

	cam.setInput(input);

	image.header.frame_id = frame_id;
	image.height = cam.height;
	image.width = cam.width;
	image.encoding = sensor_msgs::image_encodings::RGB8;

	while (ros::ok()) {
		unsigned char* ptr = cam.Update();
	
		image.header.stamp = ros::Time::now();
		int image_size = cam.width * cam.height * 3;
		image.step = cam.width * 3;
    image.data.resize(image_size);
    memcpy(&image.data[0], ptr, image_size);

    cam_info = cinfo.getCameraInfo();

    cam_info.header.frame_id = image.header.frame_id;
    cam_info.header.stamp = image.header.stamp;

    image_pub.publish(image, cam_info);

		ros::spinOnce();
	}

	return 0;
}
Esempio n. 24
0
void OSGFLevel::InitializeCamera()
{
	OSGFCamera cam(mGame);
	cam.SetFarPlane(1000);
	cam.SetNearPlane(1);
	cam.SetFovY((float)D3DX_PI*0.33);
	cam.SetLookAt(D3DXVECTOR3(0,3.50,-3.50),D3DXVECTOR3(0,0,0),D3DXVECTOR3(0,1,0));
	cam.Initialize();
	SetCamera(cam);
}
Esempio n. 25
0
int main()
{
	//~ StereoCamera cam(1); // Calibration
	
    StereoCamera cam("Stereo"); //Disparity
    cam.generate3d();
    //~ cam.testRectification();

	return 0;
}
Esempio n. 26
0
		void saveImage(std::string filename){
			std::ofstream file;
			file.open(filename);

			file << "P3" << std::endl;
			file << width_ << " " << height_ << std::endl;
			file << "255" << std::endl;

			Hitable *list[4];
			//float R = cos(M_PI / 4);
			list[0] = new Sphere(Vec3<float>(-1.5,0.0,-1.0), 0.5, new Lambertian(Vec3<float>(0.1,0.2,0.5)));
			list[1] = new Sphere(Vec3<float>(1, -100.5, -1.0), 100, new Lambertian(Vec3<float>(0.1, 0.4, 0.3)));
			list[2] = new Sphere(Vec3<float>(1.5, 0.0, -1.0), 0.5, new Metal(Vec3<float>(0.8, 0.6, 0.2),1.0));
			//list[3] = new Sphere(Vec3<float>(0.0, 0.0, -1.0), 0.5, new Dieletric(1.5));
			list[3] = new Box(Vec3<float>(0.0, -0.5, -1.5), Vec3<float>(0.5, 0.0, -1.0), new Dieletric(1.5));
			//list[4] = new Sphere(Vec3<float>(0.0, 0.0, -1.0), -0.495, new Dieletric(1.5));
			//list[4] = new Plane(Vec3<float>(-4.0, 5.0, -2.0), Vec3<float>(4.0, -1.0, -2.0), new Dieletric(1.5));
			//list[4] = new Plane(Vec3<float>(0.0, 0.0, -4.0), Vec3<float>(0.0, 1.0, 1.0), new Dieletric(1.5));
			//list[4] = new Sphere(Vec3<float>(-1.0, 0.0, -5.0), 3.5, new Lambertian(Vec3<float>(0.6, 0.4, 0.5)));
			//list[5] = new Sphere(Vec3<float>(-1.0, 0.0, -1.0), 0.5, new Dieletric(10.5));

			Hitable * world = new Hitable_list(list, 4);
			//Hitable *world = random_scene();

			Vec3<float> lookfrom(2.0, 0.0, 1.0), lookat(0.0, 0.0, -1.0);
			float dist_to_focus = (lookfrom - lookat).length();
			float aperture = 2.0;

			Camera cam(lookfrom, lookat,Vec3<float>(0,1,0), 60, float(width_/height_));
			int ns = 100;
			for (int i = height_-1; i >= 0; i--){
				for (int j = 0; j < width_; j++){

					Vec3<float> col(0.0, 0.0, 0.0);
					for (int s = 0; s < ns; s++)
					{
						float u = float(i + Rand()) / float(height_);
						float v = float(j + Rand()) / float(width_);

						Ray<float> r = cam.getRay(u, v);
						Vec3<float> p = r.point_at_parameter(2.0);
						col += color(r, world, 0);
					}

					float n = float(ns);
					col /= n;
					col = Vec3<float>(sqrt(col.x()), sqrt(col.y()), sqrt(col.z()));
					int ir = int(255.99*col.x()), ig = int(255.99*col.y()), ib = int(255.99*col.z());

					file << ir << " " << ig << " " << ib << endl;
				}
			}
			file.close();
		}
Esempio n. 27
0
// Construct/return a floating window containing the CamWnd widget
FloatingCamWndPtr GlobalCameraManager::createFloatingWindow() {
	// Create a new floating camera window widget and return it
	FloatingCamWndPtr cam(new FloatingCamWnd(_parent));

	_cameras.insert(CamWndMap::value_type(cam->getId(), cam));

	if (_activeCam == -1) {
		_activeCam = cam->getId();
	}

	return cam;
}
Esempio n. 28
0
CamWndPtr GlobalCameraManager::createCamWnd() {
	// Instantantiate a new camera
	CamWndPtr cam(new CamWnd());

	_cameras.insert(CamWndMap::value_type(cam->getId(), cam));

	if (_activeCam == -1) {
		_activeCam = cam->getId();
	}

	return cam;
}
Camera InterpolationFunction<Camera>::interpolate(Camera startvalue, Camera endvalue, float time) const {
    Vec3LinearInterpolationFunction* intfunc = new Vec3LinearInterpolationFunction();
    Vec3SphericalLinearInterpolationFunction* intfunc2 = new Vec3SphericalLinearInterpolationFunction();
    tgt::vec3 posvec = intfunc->interpolate(startvalue.getPosition(), endvalue.getPosition(), time);
    tgt::vec3 focvec = intfunc->interpolate(startvalue.getFocus(), endvalue.getFocus(), time);
    tgt::vec3 upvec = normalize(intfunc2->interpolate(startvalue.getUpVector(), endvalue.getUpVector(), time));
    /*            tgt::vec3 direction = intfunc2->interpolate(startvalue->getDirection(), endvalue->getDirection(), time);
                return new CameraNode(posvec, focvec, upvec, direction); */
    Camera cam(startvalue);
    cam.positionCamera(posvec, focvec, upvec);
    return cam;
}
bool QCamFindShift_barycentre::findBarycentre(Vector2D & center) {
   const unsigned char * img=cam().yuvFrame().Y();
   double imgSum=0, barySum=0;
   int max=0;
   center.set(0,0);
   int seuil=(maximum_+(int)average_)>>1;
   for(int j=cam().size().height()-1;
       j>=0;--j) {
      for (int i=cam().size().width()-1;
           i>=0;--i) {
         unsigned char val=img[i+j*cam().size().width()];
         imgSum += val;
         if (val>max) max=val;
         if (val>=seuil) {
            barySum+=val;
            center+=Vector2D(i,j)*val;
         }
      }
   }
   average_=imgSum/(cam().size().height()*cam().size().width());
   maximum_=max;
   if (barySum>0) {
      center/=barySum;
      return true;
   } else {
      return false;
   }
}