Ejemplo n.º 1
0
void scene::generateDefaultScene()
{

    //add bounding box

    MyRectangle *roomFloor = new MyRectangle(vector3(-70, 0, 0), vector3(-70, 0, -201), vector3(70, 0, -201),  materialConstants (0.7f,1.0f,1.0f, Rgb(0.9, 0.9, 0.3), 0));

  //Utils::rotateFloorMyRectangle(roomFloor, pii/13);
   float roomHeight = 130;
   vector<Primitive *> parallelogramSides = getParrallelogramSides(roomFloor, roomHeight);
   Primitive *leftSide = parallelogramSides[2];
   Primitive *rightSide = parallelogramSides[3];
   leftSide->setMaterial(materialConstants (1.0f,1.0f,1.0f, Rgb(1, 0.2, 0.2)));
   rightSide->setMaterial(materialConstants (1.0f,1.0f,1.0f, Rgb(0.2, 1, 0.2)));


   primitives.insert( primitives.end(), parallelogramSides.begin(), parallelogramSides.end() );

   //add box
   MyRectangle *base = new MyRectangle(vector3(-15, 0, -20), vector3(-45, 0, -20), vector3(-40, 0, -50),  materialConstants (1.0f,1.0f,1.0f, Rgb(0.9, 0.9, 0.3), 0));
   rotateFloorMyRectangle(base, pii/10);
  float boxHeight = 50;

  vector<Primitive *> baseSides = getParrallelogramSides(base, boxHeight);

   primitives.insert( primitives.end(), baseSides.begin(), baseSides.end() );



//add sphere----------------------------------------

  // Sphere *sp = new Sphere(20, vector3(-30, -20, -50), materialConstants (1.0f,0.2f, 1.0f,  Rgb(0.9, 0.8, 0.3), 1, 0.9));//glossy
 //  Sphere *sp = new Sphere(20, vector3(-30, -20, -50), materialConstants (1.0f,0.2f, 1.0f,  Rgb(0.9, 0.8, 0.3), 3, 0.9, 1.5));//refraction

   Sphere *spMirror = new Sphere(12, vector3(-30, -boxHeight-12, -35), materialConstants (1.0f,0.2f, 1.0f,  Rgb(0.8, 0.8, 0.8), 2, 0));//mirror
   primitives.push_back(spMirror);

//add light----------------------------------------
  MyRectangle *lightSource = new MyRectangle(vector3(-50, -roomHeight + 0.5f, -20), vector3(-50, -roomHeight + 0.5f, -150), vector3(50, -roomHeight + 0.5f, -150),  materialConstants (Rgb(0.8, 1, 1)));
 //  MyRectangle *lightSource = new MyRectangle(vector3(-30, -roomHeight + 0.5f, -30), vector3(-30, -roomHeight + 0.5f, -110), vector3(30, -roomHeight + 0.5f, -110),  materialConstants (Rgb(0.8, 1, 1)));

   lightSource->setIslightSource(true);
   cout << " LIGHT : " << lightSource->ifIsLightSource() << endl;

   primitives.push_back(lightSource);
//cylindre-------------------------------------------
   cylindre * cy = new cylindre(50, vector3(0,-1,0), vector3(37, 0, -30),17, materialConstants(1.0f,0.4f,1.0f, Rgb(1, 1, 1) , 1, 2.5));
   QImage fanta = QImage("fanta.jpg");
   cout << "height :"<< fanta.height() << endl;
   cout << "width : "<< fanta.width() << endl;

   cy->setTexture(fanta);

   primitives.push_back(cy);
   //refracting----------------------------------------------
   Sphere *sp = new Sphere(12, vector3(10, -12, -72), materialConstants (1.0f,0.2f, 1.0f,  Rgb(0.9, 0.8, 0.3), 3, 0.9, 1.2));//refraction
   primitives.push_back(sp);

   cout << "  i'm alive " << endl;
}
Ejemplo n.º 2
0
Rgb HistFunctor::operator() ( double v) const {
    if( ! std::isfinite(v))
        return Rgb(0,0,0);
    if( v < min_)
        return Rgb(255,0,0);
    if( v > max_)
        return Rgb(0,255,0);
    int gray = round(v * la_ + lb_);
    if( gray < 0) gray = 0; if( gray > 255) gray = 255;

    return Rgb(gray, gray, gray);
}
Ejemplo n.º 3
0
void ColorMap::interpose(int base)
{
	/*保证基数大于0*/
	assert(base>0);

	int i,k,j;
	float w;
	float increaseStep;
	float startStep;
	Rgb c;
	w=1;	
	k=0;
	increaseStep = step/(base+1);
	for(i=1;i<32;i++)
	{
		startStep = min + (k++)*step;
		for(j=0;j<base;j++)
		{
			w=(float)j/base;
			c=Rgb(
				(int)(useMap[i-1].red()+(useMap[i].red()-useMap[i-1].red())*w),
				(int)(useMap[i-1].green()+(useMap[i].green()-useMap[i-1].green())*w),

				(int)(useMap[i-1].blue()+(useMap[i].blue()-useMap[i-1].blue())*w)
				);

			colorMap->insert(std::make_pair(startStep+increaseStep*j,c));

			colorindex.push_back(startStep+increaseStep*j);
		}
	}
	quicksort(colorindex,0,colorindex.size()-1);
}
Ejemplo n.º 4
0
void MyWindow::draw ()
{   int i,j,k,f;
	double zre,zim,wre,wim,wrenew,deltax,deltay;
	ULONG color;
	bitmap->directcolor();
	deltax=(Xmax-Xmin)/width();
	deltay=(Ymax-Ymin)/height();
	for (i=0; i<width(); i++)
	{   zre=Xmin+i*deltax;
		for (j=0; j<=height(); j++)
		{   wre=zre;
			wim=zim=Ymin+j*deltay;
			for (k=0; k<Iterations; k++)
			{	if (wim*wim+wre*wre>16) break;
				wrenew=wre*wre-wim*wim+zre;
				wim=2*wre*wim+zim;
				wre=wrenew;
			}
			if (k<Iterations)
			{   f=255l*k/Iterations;
				color=Rgb(0,255-f,f);
			}
			else color=0;
			bitmap->point(i,j,color);
		}
		if (i%10==0) copy();
	}
	window.update();
}
Ejemplo n.º 5
0
int Color::getBlue() const
{
  switch (getType()) {

    case Color::MaskType:
      return 0;

    case Color::RgbType:
      return m_value.rgb.b;

    case Color::HsvType:
      return Rgb(Hsv(m_value.hsv.h,
                     double(m_value.hsv.s) / 100.0,
                     double(m_value.hsv.v) / 100.0)).blue();

    case Color::GrayType:
      return m_value.gray;

    case Color::IndexType: {
      int i = m_value.index;
      ASSERT(i >= 0 && i < get_current_palette()->size());

      return _rgba_getb(get_current_palette()->getEntry(i));
    }

  }

  ASSERT(false);
  return -1;
}
Ejemplo n.º 6
0
Rgb SpotLight::getRgb(const Vector3f& point)
{
	Vector3f L = point - this->center;
	float d = L.getLength();
	Vector3f& D = direction;
	Rgb retVal = Rgb(0,0,0);

	//float Kc = 1;
	//float Kl = 0;
	//float Kq = 0;

	float Kc = 0;
	float Kl = 1;
	float Kq = 0.1;

	float dot = Vector3f::dotProduct(D, L);
	float angleBetween = acosf( dot / (D.getLength()*L.getLength()) );
	if (abs(angleBetween) > this->angle*2.0/180){
		return retVal;
	}
	float d2 = pow(d,2);

	retVal.x		= (rgb.x   * dot) / (Kc + Kl*d + Kq*d2);
	retVal.y		= (rgb.y * dot) / (Kc + Kl*d + Kq*d2);
	retVal.z		= (rgb.z  * dot) / (Kc + Kl*d + Kq*d2);

	retVal.x		= (retVal.x   > 1) ? 1 : retVal.x;
	retVal.y		= (retVal.y > 1) ? 1 : retVal.y;
	retVal.z		= (retVal.z  > 1) ? 1 : retVal.z;
	return retVal;
}
Ejemplo n.º 7
0
Rgb ProjectionPane::getPixel(int i, int j)
{
    if ((i >= 0) & (j >= 0)
            &(i < height) & (j < width))
    return *pane[i][j];
    else  return Rgb(0,0,0);
}
Ejemplo n.º 8
0
Rgb ModelFactory::readColor()
{
    bool eof;
    uchar r = readerMtl->readFloat(eof) * 255 + 0.5;
    uchar g = readerMtl->readFloat(eof) * 255 + 0.5;
    uchar b = readerMtl->readFloat(eof) * 255 + 0.5;
    return Rgb(r, g, b);
}
Ejemplo n.º 9
0
void ScavTaskColorShirt::callback_human_detection(const PointCloud::ConstPtr& msg) {

    int color_cnt = 0; 

    switch (color) {
        case RED:       baseline = Rgb(255.0, 0.0, 0.0);    break;
        case BLUE:      baseline = Rgb(0.0, 0.0, 255.0);    break;
        case GREEN:     baseline = Rgb(0.0, 255.0, 0.0);    break;
        case YELLOW:    baseline = Rgb(255.0, 255.0, 0.0);  break; 
        case ORANGE:    baseline = Rgb(191.0, 87.0, 0.0);   break;
    }

    BOOST_FOREACH (const pcl::PointXYZRGB& pt, msg->points) {

        // here we assume the waist height is 90cm, and neck height is 160cm; 
        // the robot sensor's height is 60cm
        if (pt.y > SHIRT_HEIGHT_BOTTOM and pt.y < SHIRT_HEIGHT_TOP 
                and this->getColorDistance( &pt, &baseline) < DISTANCE_TO_COLOR) {            
            color_cnt++;
        }
    }

    float ratio = (float) color_cnt / (float) msg->points.size();

    ROS_INFO("ratio is %f", ratio);

    if (ratio > COLOR_RATIO && ros::ok()) { 

        ROS_INFO_STREAM("person wearing" << color << "shirt detected"); 
        
        boost::posix_time::ptime curr_time = boost::posix_time::second_clock::local_time();  
        std::string time_str = boost::posix_time::to_simple_string(curr_time); 

        cv_bridge::CvImageConstPtr cv_ptr = cv_bridge::toCvShare(image, sensor_msgs::image_encodings::BGR8);
        
        if (false == boost::filesystem::is_directory(directory)) {
            boost::filesystem::path tmp_path(directory);
            boost::filesystem::create_directory(tmp_path);
        }
        path_to_image = directory + "color_shirt_" + time_str; 
        cv::imwrite(path_to_image, cv_ptr->image);
    }
}
Ejemplo n.º 10
0
void Car::display(const Transform &viewProjectionTransform,
                  Transform worldTransform)
{
    //
    // Copy your previous (PA08) setting of `modelTransform` here.
    //

    if (path == NULL)
    {
        Transform identity;
        modelTransform = identity;
    }
    else
    {
        // Perform in reverse order (c -> b -> a)
        modelTransform = path->coordinateFrame(u);   // "Set?"   
        modelTransform.scale(0.15, 0.075, 0.15);     // Scale
        modelTransform.translate(0.0, 0.25, 0.0);    // Translate
    }       

    if (eadsShaderProgram) { // will be NULL in the template
        double specFrac = 0.25; // fraction of reflected power that's specular
        Rgb ambDiffBaseRgb = (1.0 - specFrac) * baseRgb;
        Transform identityTransform;

        eadsShaderProgram->setEmittance(blackColor);
        eadsShaderProgram->setAmbient(0.2 * ambDiffBaseRgb);
        eadsShaderProgram->setDiffuse(0.8 * ambDiffBaseRgb);
        eadsShaderProgram->setSpecular(Rgb(specFrac, specFrac, specFrac),
                                       10.0);
        worldTransform *= modelTransform;
        eadsShaderProgram->setModelViewProjectionMatrix(
            viewProjectionTransform * worldTransform);
        eadsShaderProgram->setWorldMatrix(worldTransform);
        eadsShaderProgram->setNormalMatrix(
            worldTransform.getNormalTransform());
        eadsShaderProgram->start();
    }

    // `solidOfRotation` will be NULL in the unmodified template.
    if (solidOfRotation) {
        solidOfRotation->draw();
        const double quillLength = 0.04;
        solidOfRotation->displayHedgehogIfRequested(viewProjectionTransform,
                                                    worldTransform,
                                                    quillLength);
    }

    if (controller.axesEnabled)
        coordinateAxes->display(viewProjectionTransform, worldTransform);
}
Ejemplo n.º 11
0
Rgb ColormapFunction::operator()( double x) {
    if( ! std::isfinite( x))
        return Rgb(0,0,0);

////    x = x - 0.5 * scale1_;
////    x = (x-0.5) * exp( - 3 * scale2_) + 0.5;

//// version 1
////    double eps = 0.001;
////    double xx = (scale1_ + 1)/2;
////    double yy = (scale2_ + 1)/2;
////    xx = xx * ( 1 - 2 * eps) + eps;
////    yy = yy * ( 1 - 2 * eps) + eps;
////    double a = log(yy) / log(xx);
////    x = pow( x, a);

//// version 2
////    double max = 10;
////    double xx = (scale1_ + 1)/2;
////    double yy = scale2_;
////    double a = fabs(yy) * (max-1) + 1;
////    a = xx * (a-1) + 1;
////    if( yy > 0) a = 1/a;
////    x = pow( x, a);

//// version 3
//    double maxndig = 10;
//    double ndig = (scale2_ + 1) / 2 * maxndig;
//    double expo = std::pow( 2.0, ndig);
//    double xx = pow(scale1_ * 2, 3) / 8.0;
//    m_gamma = fabs(xx) * expo + 1;
//    if( scale1_ < 0) m_gamma = 1 / m_gamma;
    x = std::pow( x, m_gamma);

    if( reverse_) x = 1 - x;
    Rgb rgb( 255 * red_(x), 255 * green_(x), 255 * blue_(x));
    if( invert_) {
        rgb.r = 255 - rgb.r;
        rgb.g = 255 - rgb.g;
        rgb.b = 255 - rgb.b;
    }
    rgb.r = round ( rgb.r * redScale_);
    rgb.g = round ( rgb.g * greenScale_);
    rgb.b = round ( rgb.b * blueScale_);
    return rgb;
}
Ejemplo n.º 12
0
Rgb operator*(Rgb lhs, double rhs)
{
  return Rgb(lhs.r * rhs, lhs.g * rhs, lhs.b * rhs, lhs.a * rhs);
}
Ejemplo n.º 13
0
Rgb cylindre::getLightLuminance(vector3 currPoint, vector3 objectNormal, vector3 lightPoint){
    cout << "not implemented" << endl;
    return Rgb(0,0,0);
}
Ejemplo n.º 14
0
CachedRgbFunction::CachedRgbFunction()
{
    init( HistogramColormapFunctor(0,1,ColormapFunction::heat()), 0, 1, 10000, Rgb(0,0,0));
}
Ejemplo n.º 15
0
 inline Rgb operator /( const Z& val ) const
 {
   return Rgb( T( ( Z )( ( *this )( 0 ) ) / val ),
               T( ( Z )( ( *this )( 1 ) ) / val ),
               T( ( Z )( ( *this )( 2 ) ) / val ) );
 }
Ejemplo n.º 16
0
 inline Rgb operator *( const Z& val ) const
 {
   return Rgb( T( ( Z )( *this )( 0 ) * val ),
               T( ( Z )( *this )( 1 ) * val ),
               T( ( Z )( *this )( 2 ) * val ) );
 }
Ejemplo n.º 17
0
Archivo: ease.hpp Proyecto: eco/vibrant
 Rgb operator()(Line& line) const { return Rgb(0, 0, 0); }
Ejemplo n.º 18
0
// Light that bounces off only once
Rgb Dielectric::directRadiance(Intersection *intersection, Ray ray, Light *light)
{
	// No contribution
	return Rgb(0.0, 0.0, 0.0);
}
Ejemplo n.º 19
0
Rgb operator-(const Rgb& rhs) { return Rgb(-rhs.r, -rhs.g, -rhs.b, -rhs.a); }
Ejemplo n.º 20
0
Rgb operator+(Rgb lhs, Rgb rhs)
{
  return Rgb(lhs.r + rhs.r, lhs.g + rhs.g, lhs.b + rhs.b, lhs.a + rhs.a);
}
Ejemplo n.º 21
0
Rgb operator+(double lhs, Rgb rhs)
{
  return Rgb(lhs + rhs.r, lhs + rhs.g, lhs + rhs.b, lhs + rhs.a);
}
Ejemplo n.º 22
0
Rgb operator+(Rgb lhs, double rhs)
{
  return Rgb(lhs.r + rhs, lhs.g + rhs, lhs.b + rhs, lhs.a + rhs);
}
Ejemplo n.º 23
0
	if(mapIndex>(mapsize-1))
		return;

	currentMap=mapIndex;
	memcpy((char*)useMap,(char*)maps[mapIndex],sizeof(useMap)); 
}

void ColorMap::setRange(float minValue,float maxValue)
{
	max = maxValue;
	min = minValue;
	initial();
}

Rgb ColorMap::sebcolors[]={
	Rgb(144,144,144),Rgb(0,0,255),Rgb(0,64,255),Rgb(0,95,255),
	Rgb(0,127,255),Rgb(0,159,255),Rgb(0,191,255),Rgb(0,223,255),
	Rgb(0,255,255),Rgb(32,255,223),Rgb(64,255,191),Rgb(95,255,159),
	Rgb(127,255,127),Rgb(159,255,95),Rgb(191,255,64),Rgb(223,255,32),
	Rgb(255,255,0),Rgb(255,223,0),Rgb(255,191,0),Rgb(255,159,0),
	Rgb(255,127,0),Rgb(255,95,0),Rgb(255,64,0),Rgb(255,32,0),
	Rgb(255,0,0),Rgb(255,0,64),Rgb(255,0,95),Rgb(255,0,127),
	Rgb(255,0,159),Rgb(255,0,191),Rgb(255,0,223),Rgb(255,0,255)
};

Rgb ColorMap::gathercolors[]={
	Rgb(0,0,255),Rgb(0,0,255),Rgb(1,1,255),Rgb(4,4,255),
	Rgb(8,8,255),Rgb(14,14,255),Rgb(22,22,255),Rgb(33,33,255),
	Rgb(45,45,255),Rgb(60,60,255),Rgb(79,79,255),Rgb(100,100,255),
	Rgb(124,124,255),Rgb(152,152,255),Rgb(183,183,255),Rgb(217,217,255),
	Rgb(255,255,255),Rgb(255,217,217),Rgb(255,183,183),Rgb(255,152,152),
Ejemplo n.º 24
0
Rgb operator-(Rgb lhs, Rgb rhs)
{
  return Rgb(lhs.r - rhs.r, lhs.g - rhs.g, lhs.b - rhs.b, lhs.a - rhs.a);
}
Ejemplo n.º 25
0
Rgb operator*(Rgb lhs, Rgb rhs)
{
  return Rgb(lhs.r * rhs.r, lhs.g * rhs.g, lhs.b * rhs.b, lhs.a * rhs.a);
}
Ejemplo n.º 26
0
/**
 * @brief constructor for QUProfileController
 * @param parent
 * @param wcsHelper - coordinate/value formatter
 * @param id
 * @param title
 * @param willDoFitting
 */
QUProfileController::QUProfileController(QObject * parent,
                                         const QString & id,
                                         const QString & title)
    : QObject(parent)
{
    m_myId = id;
    m_pwPrefix = QString( "/quprofile-%1/").arg( m_myId);
    m_viewName = QString( "quprofile-%1").arg( m_myId);
    m_initialized = false;

    // create a render buffer
    m_buffer = QImage( 2, 2, QImage::QImage::Format_RGB888);

    // setup fonts
    m_labelFont = QFont( "Helvetica", 8);
    m_captionFont = QFont( "Helvetica", 10, QFont::Normal);
    m_labelFontMetrics.reset( new QFontMetricsF( m_labelFont));
    m_captionFontMetrics.reset( new QFontMetricsF( m_captionFont));

    // register a view with pureweb
    CSI::PureWeb::Server::ViewImageFormat viewImageFormat;
    viewImageFormat.PixelFormat = CSI::PureWeb::PixelFormat::Rgb24;
    viewImageFormat.ScanLineOrder = CSI::PureWeb::ScanLineOrder::TopDown;
    viewImageFormat.Alignment = 4;
    GetStateManager().ViewManager().RegisterView(
                m_viewName.toStdString(), this);
    GetStateManager().ViewManager().SetViewImageFormat(
                m_viewName.toStdString(), viewImageFormat);
    GetStateManager ().ViewManager ().SetViewInteracting(
                m_viewName.toStdString(), false);

    // register PureWeb callback for all commands
    GetStateManager().CommandManager().AddUiHandler(
                ("quprofile-" + m_myId).toStdString(),
                CSI::Bind(this, & QUProfileController::commandDispatcher ));

    // cursor requests are arriving as state changes
    GetStateManager().XmlStateManager().AddValueChangedHandler(
                QString("/requests/quprofile-%1/mouseHover").arg(m_myId).toStdString(),
                CSI::Bind(this, &QUProfileController::mouseHoverRequestCB));

    // set some defaults
    m_total = 0;
    m_cursorIndex = -1;
    m_autoZoom = true;

    // setup the colormap function (cached)
    {
        ColormapFunction cmap = ColormapFunction::sunbow();
        cmap.setRgbScales( 0.5, 0.5, 0.5);
        HistogramColormapFunctor hfun( 0, 1, cmap);
        m_cmap.reset( new CachedRgbFunction( hfun, 0, 1, 256, Rgb(0,0,0)));
    }

    m_updateTimer = new QTimer( this);
    m_updateTimer->setSingleShot( true);
    m_updateTimer->setInterval(1);

    // set up the graph labelers
    m_vertLabeler = std::make_shared< Plot2dLabelers::BasicLabeler >();
//    m_vertLabeler-> setDual( false);
    m_horizLabeler = std::make_shared< Plot2dLabelers::BasicLabeler >();
//    m_horizLabeler-> setDual( false);

    // connect our update timer to callback
    connect( m_updateTimer, SIGNAL(timeout()), this, SLOT(updateTimerCB()));

    // create global variables reflecting the state of the object
    m_ignoreVarCallbacks = true;
    binder( this, m_vars.dotSize, "dotSize", 2.5);
    binder( this, m_vars.transparency, "transparency", 0.5);
    binder( this, m_vars.showCursor, "showCursor", true);
    binder( this, m_vars.showMean, "showMean", true);
    binder( this, m_vars.showGrid, "showGrid", true);
    binder( this, m_vars.showSunbow, "showSunbow", true);
    binder( this, m_vars.showConnectingLines, "showConnect", false);
    binder( this, m_vars.visibleOnClient, "visibleOnClient", false);

    // outgoing variables (no need to assign callbacks to these)
    m_vars.qVal.reset( new GlobalState::StringVar( m_pwPrefix + "q"));
    m_vars.uVal.reset( new GlobalState::StringVar( m_pwPrefix + "u"));
    m_vars.qMean.reset( new GlobalState::StringVar( m_pwPrefix + "qmean"));
    m_vars.uMean.reset( new GlobalState::StringVar( m_pwPrefix + "umean"));
    m_vars.frame.reset( new GlobalState::StringVar( m_pwPrefix + "frame"));
    m_vars.title.reset( new GlobalState::StringVar( m_pwPrefix + "title"));
    m_vars.title-> set( title);

    // unsuspend callback
    m_ignoreVarCallbacks = false;

    markDirty();
}
Ejemplo n.º 27
0
Rgb operator/(Rgb lhs, double rhs)
{
  return Rgb(lhs.r / rhs, lhs.g / rhs, lhs.b / rhs, lhs.a / rhs);
}