コード例 #1
0
ファイル: cvfColor4.cpp プロジェクト: akva2/ResInsight
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
Color4f::Color4f(const Color3f& rgbColor, float alpha)
{
    m_rgba[0] = rgbColor.r();
    m_rgba[1] = rgbColor.g();
    m_rgba[2] = rgbColor.b();
    m_rgba[3] = alpha;
}
コード例 #2
0
ファイル: cvfColor4.cpp プロジェクト: akva2/ResInsight
//--------------------------------------------------------------------------------------------------
/// Construct from 3 component RGB color. Alpha value will be set to 1.0
//--------------------------------------------------------------------------------------------------
Color4f::Color4f(const Color3f& rgbColor)
{
    m_rgba[0] = rgbColor.r();
    m_rgba[1] = rgbColor.g();
    m_rgba[2] = rgbColor.b();
    m_rgba[3] = 1.0f;
}
コード例 #3
0
ファイル: Color3f.cpp プロジェクト: 4og/guacamole
Color3f operator-(Color3f const& lhs, Color3f const& rhs) {
  Color3f result;
  result.r(lhs.r() - rhs.r());
  result.g(lhs.g() - rhs.g());
  result.b(lhs.b() - rhs.b());
  return result;
}
コード例 #4
0
// select all visible nodes
UInt32 RenderAction::selectVisibles(void)
{
    if(getFrustumCulling() == false)
        return getNNodes();

    useNodeList();

    Color3f col;

    UInt32 count = 0;

    for(UInt32 i = 0; i < getNNodes(); i++)
    {
        if(isVisible(getNode(i)))
        {
            col.setValuesRGB(0,1,0);

            addNode(getNode(i));

            ++count;
        }
        else
        {
            col.setValuesRGB(1,0,0);
        }

        if(getVolumeDrawing())
        {
            dropVolume(this, getNode(i), col);
        }
    }

    return count;
}
コード例 #5
0
void FrameBufferObject::
clear_color_buffers(RenderContext const& ctx, Color3f const& color) {

    if (ctx.id < fbos_.size())
        ctx.render_context->clear_color_buffers(
                                fbos_[ctx.id], math::vec4(color.r(), color.g(),
                                                          color.b(), 0.f));
}
コード例 #6
0
void ShaderProgram::
set_color3f(RenderContext const& context, std::string const& color_name,
            Color3f const& color) {

    if (programs_.size() > context.id)
        programs_[context.id]->uniform(
                    color_name, math::vec3(color.r(), color.g(), color.b()));
}
コード例 #7
0
ファイル: cvfUniform.cpp プロジェクト: akva2/ResInsight
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void UniformFloat::set(const Color3f& value)
{
    m_type = FLOAT_VEC3;
    m_data.resize(3);
    m_data[0] = value.r();
    m_data[1] = value.g();
    m_data[2] = value.b();
}
コード例 #8
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
String PropertyXmlSerializer::valueTextFromColor3fVariant(const Variant& variant)
{
    CVF_ASSERT(variant.type() == Variant::COLOR3F);
    Color3f val = variant.getColor3f();

    String txt =  String::number(val.r()) + " " + String::number(val.g()) + " " + String::number(val.b());
    return txt;
}
コード例 #9
0
ファイル: direct_mats.cpp プロジェクト: valdersoul/NoriV2
    Color3f Li(const Scene *scene, Sampler *sampler, const Ray3f &ray) const {
        /* Find the surface that is visible in the requested direction */
        Intersection its;

        //check if the ray intersects the scene
        if (!scene->rayIntersect(ray, its)) {
            //check if a distant disk light is set
            const Emitter* distantsDisk = scene->getDistantEmitter();
            if(distantsDisk == nullptr ) return Color3f(0.0f);

            //sample the distant disk light
            return distantsDisk->sampleL(ray.d);
        }

        //get the radiance of hitten object
        Color3f Le(0.0f, 0.0f, 0.0f);
        if (its.mesh->isEmitter()  ) {
            const Emitter* areaLightEM = its.mesh->getEmitter();
            const areaLight* aEM = static_cast<const areaLight *> (areaLightEM);
            Le = aEM->sampleL(-ray.d, its.shFrame.n, its);
        }

        //get the asigned BSDF
        const BSDF* curBSDF = its.mesh->getBSDF();

        Color3f Ld(0.0f, 0.0f, 0.0f);
        Color3f f(0.0f, 0.0f, 0.0f);
        Color3f totalLight(0.0f, 0.0f, 0.0f);

        //transform to the local frame
        //create a BRDF Query
        BSDFQueryRecord query = BSDFQueryRecord(its.toLocal(-ray.d), Vector3f(0.0f), EMeasure::ESolidAngle);

        //sample the BRDF
        Color3f mats =  curBSDF->sample(query, sampler->next2D());

        if(mats.maxCoeff() > 0.0f) {
            //Check for the light source
            Vector3f wo = its.toWorld(query.wo);
            Ray3f shadowRay(its.p, wo);
            Intersection itsShadow;
            if (scene->rayIntersect(shadowRay, itsShadow)) {
                //intersection check if mesh is emitter
                if(itsShadow.mesh->isEmitter()){
                    Ld = itsShadow.mesh->getEmitter()->radiance();
                }
            } else {
                //check for distant disk light
                const Emitter* distantsDisk = scene->getDistantEmitter();
                if(distantsDisk != nullptr ) Ld = distantsDisk->sampleL(wo);
            }

            totalLight += Ld * mats;
        }

        return Le + totalLight;
    }
コード例 #10
0
ファイル: View.cpp プロジェクト: tmichi/meshview
void
View::init ( void )
{
        ::glEnable( GL_CULL_FACE );
        ::glEnable ( GL_DEPTH_TEST );
        ::glEnable ( GL_LIGHT0 );
        ::glShadeModel ( GL_FLAT );
        const Color3f bg = this->_model.getPreference().getBackgroundColor();
        ::glClearColor ( bg.x(), bg.y(), bg.z(), 1 );
        return;
}
コード例 #11
0
void CursorTrail::DrawLine2D(float _fSize, Color3f color) {
	
	if(iNbOldCoord < 2) {
		return;
	}
	
	float incSize = _fSize / iNbOldCoord;
	float currentSize = incSize;
	
	Color3f incColor = Color3f(color.r / iNbOldCoord, color.g / iNbOldCoord, color.b / iNbOldCoord);
	
	Color3f currentColor = incColor;
	
	GRenderer->SetBlendFunc(BlendDstColor, BlendInvDstColor);
	GRenderer->ResetTexture(0);
	GRenderer->SetRenderState(Renderer::AlphaBlending, true);
	
	TexturedVertex v[4];
	v[0].p.z = v[1].p.z = v[2].p.z = v[3].p.z = 0.f;
	v[0].rhw = v[1].rhw = v[2].rhw = v[3].rhw = 1.f;
	
	v[0].color = v[2].color = currentColor.toRGB();
	
	if(!ComputePer(iOldCoord[0], iOldCoord[1], &v[0], &v[2], currentSize)) {
		v[0].p.x = v[2].p.x = iOldCoord[0].x;
		v[0].p.y = v[2].p.y = iOldCoord[1].y;
	}
	
	for(int i = 1; i < iNbOldCoord - 1; i++) {
		
		currentSize += incSize;
		currentColor += incColor;
		
		if(ComputePer(iOldCoord[i], iOldCoord[i + 1], &v[1], &v[3], currentSize)) {
			
			v[1].color = v[3].color = currentColor.toRGB();
			EERIEDRAWPRIM(Renderer::TriangleStrip, v, 4);
			
			v[0].p.x = v[1].p.x;
			v[0].p.y = v[1].p.y;
			v[0].color = v[1].color;
			v[2].p.x = v[3].p.x;
			v[2].p.y = v[3].p.y;
			v[2].color = v[3].color;
		}
		
	}
	
	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
}
コード例 #12
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RenderStateMaterial_FF::setAmbientAndDiffuse(const Color3f& color)
{
    CVF_ASSERT(color.isValid());

    m_ambient = color;
    m_diffuse = color;
}
コード例 #13
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
TEST(VariantTest, TypeColor3f)
{
    const Color3f val(0.2f, 0.2f, 0.3f);
    Variant var(val);
    ASSERT_EQ(Variant::COLOR3F, var.type());
    ASSERT_TRUE(var.isValid());

    Color3f v = var.getColor3f();
    ASSERT_EQ(val.r(), v.r());
    ASSERT_EQ(val.g(), v.g());
    ASSERT_EQ(val.b(), v.b());
}
コード例 #14
0
ファイル: texture.cpp プロジェクト: ArkLeadr/Projet-LEADR
bool Texture::loadFromMaterialColor(Color3f matColor) {
    GL(glBindTexture(GL_TEXTURE_2D, m_tex));

    GL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_FLOAT, matColor.data()));

    GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
    GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));

    return true;
}
コード例 #15
0
    void apply_threshold(const double threshold, Image& image)
    {
        const CanvasProperties& props = image.properties();

        for (size_t y = 0; y < props.m_canvas_height; ++y)
        {
            for (size_t x = 0; x < props.m_canvas_width; ++x)
            {
                Color3f color;
                image.get_pixel(x, y, color);

                if (color[0] < threshold)
                    color.set(0.0f);
                else color.set(1.0f);

                image.set_pixel(x, y, color);
            }
        }
    }
コード例 #16
0
void ColorSource::initialize_from_color3(const ColorEntity& color_entity)
{
    Color3f color;

    const ColorValueArray& values = color_entity.get_values();
    if (values.size() == 1)
        color.set(values[0]);
    else if (values.size() == 3)
        color = Color3f(values[0], values[1], values[2]);
    else
    {
        m_scalar = ScalarInput(0.0);
        m_linear_rgb.set(0.0f);
        m_spectrum.set(0.0f);
        return;
    }

    m_scalar = static_cast<double>(color[0]);

    switch (color_entity.get_color_space())
    {
      case ColorSpaceLinearRGB:
        m_linear_rgb = color;
        break;

      case ColorSpaceSRGB:
        m_linear_rgb = srgb_to_linear_rgb(color);
        break;

      case ColorSpaceCIEXYZ:
        m_linear_rgb = ciexyz_to_linear_rgb(color);
        break;

      default:
        assert(!"Invalid color space.");
        break;
    }

    m_spectrum = m_linear_rgb;
}
コード例 #17
0
ファイル: warp.cpp プロジェクト: valdersoul/NoriV2
float Warp::squareToHSWPDF(const Point2f &p, HSWrapper *testWrapper) {

    float total = testWrapper->m_totalLum;
    float height = testWrapper->m_lightprob.rows();
    float width = testWrapper->m_lightprob.cols();
    float fPixH = height * p(1);
    float fPixW = width * p(0);
    int y = int(std::min(height - 1.0f ,std::floor(fPixH)));
    int x = int(std::min(width  - 1.0f ,std::floor(fPixW)));

    int yNext = y + 1;
    int xNext = x + 1;

    Color3f Q11 = testWrapper->m_lightprob(y, x);
    Color3f Q21 = testWrapper->m_lightprob(y, std::min(int(width -1.0f), xNext));
    Color3f Q12 = testWrapper->m_lightprob(std::min(int(height -1.0f), yNext), x);
    Color3f Q22 = testWrapper->m_lightprob(std::min(int(height -1.0f), yNext), std::min(int(width -1.0f), xNext));

    float fact1 = ((xNext - fPixW) / (xNext - x));
    float fact2 = ((fPixW - x) / (xNext - x));

    Color3f R1 = fact1 * Q11 + fact2 * Q21;
    Color3f R2 = fact1 * Q12 + fact2 * Q22;

    fact1 = ((yNext - fPixH) / (yNext - y));
    fact2 = ((fPixH - y) / (yNext - y));

    Color3f result = fact1 * R1 + fact2 * R2;

    float lum = result.getLuminance();
    if (lum < 0) {
        cout << "Negative luminance detected : " << lum << endl;
    }
    float pdf = lum / total;

    return pdf;

}
コード例 #18
0
ファイル: ColorTest.cpp プロジェクト: JanDupal/magnum
void ColorTest::access() {
    Color3f c3(15, 255, 10);
    const Color3f cc3(15, 255, 10);

    CORRADE_COMPARE(c3.r(), 15);
    CORRADE_COMPARE(c3.g(), 255);
    CORRADE_COMPARE(c3.b(), 10);
    CORRADE_COMPARE(cc3.r(), 15);
    CORRADE_COMPARE(cc3.g(), 255);
    CORRADE_COMPARE(cc3.b(), 10);

    Color4 c4(125, 98, 51, 22);
    const Color4f cc4(125, 98, 51, 22);

    CORRADE_COMPARE(c4.r(), 125);
    CORRADE_COMPARE(c4.g(), 98);
    CORRADE_COMPARE(c4.b(), 51);
    CORRADE_COMPARE(c4.a(), 22);
    CORRADE_COMPARE(cc4.r(), 125);
    CORRADE_COMPARE(cc4.g(), 98);
    CORRADE_COMPARE(cc4.b(), 51);
    CORRADE_COMPARE(cc4.a(), 22);
}
コード例 #19
0
ファイル: decoObjects.cpp プロジェクト: AlohaWu/M.A.R.S.
    void drawArrow(Vector2f const& from,  Vector2f const& to, Color3f const& color, float width) {

        Vector2f direction((to-from).normalize()*width*0.5f);
        Vector2f normal(direction.y_, -direction.x_);

        glBlendFunc(GL_ONE, GL_ONE);
        glLineWidth(width);

        glBegin(GL_TRIANGLES);
            (color*0.5f).gl3f();
            glVertex2f(from.x_,from.y_);

            color.gl3f();
            glVertex2f(to.x_-normal.x_,to.y_-normal.y_);
            glVertex2f(to.x_+normal.x_,to.y_+normal.y_);

            glVertex2f(to.x_+direction.x_*3.f,to.y_+direction.y_*3.f);
            glVertex2f(to.x_+normal.x_*2.f,to.y_+normal.y_*2.f);
            glVertex2f(to.x_-normal.x_*2.f,to.y_-normal.y_*2.f);
        glEnd();
    }
コード例 #20
0
MaterialTransitPtr OctreeVisualization::createMatFilled(OctreePtr tree,
                                                        const Octree::OTNodePtr node,
                                                        const Color3f& CoolColor,
                                                        const Color3f& HotColor,
                                                        Real32 Alpha,
                                                        BlendChunk* BaseBlendChunk,
                                                        PolygonChunk* BasePolygonChunk
                                                       )
{
    //Calculate the Color
    //Real32 t = static_cast<Real32>(node->getDepth())/static_cast<Real32>(tree->getDepth());
    //Color3f NodeColor(t*HotColor + (1.0f-t)*CoolColor);
    Color3f NodeColor;
    Color4f NodeColorWithAlpha;
    if(node->getContainsObstacles())
    {
        NodeColor = HotColor;
        NodeColorWithAlpha.setValuesRGBA(NodeColor.red(),NodeColor.green(),NodeColor.blue(),0.55);
    }
    else
    {
        NodeColor = CoolColor;
        NodeColorWithAlpha.setValuesRGBA(NodeColor.red(),NodeColor.green(),NodeColor.blue(),0.05);
    }

    MaterialChunkRecPtr    DefaultMatChunk = MaterialChunk::create();
    DefaultMatChunk->setAmbient(NodeColorWithAlpha);
    DefaultMatChunk->setDiffuse(NodeColorWithAlpha);

    ChunkMaterialRecPtr NodeMat = ChunkMaterial::create();
    NodeMat->setSortKey(1);
    NodeMat->addChunk(BaseBlendChunk);
    NodeMat->addChunk(BasePolygonChunk);
    NodeMat->addChunk(DefaultMatChunk);

    return MaterialTransitPtr(NodeMat);
}
コード例 #21
0
ファイル: MagicFlare.cpp プロジェクト: Batora07/ArxLibertatis
void ARX_MAGICAL_FLARES_Update() {

	if(!flarenum)
		return;

	shinum++;
	if(shinum >= 10) {
		shinum = 1;
	}

	long TICKS = long(arxtime) - FRAMETICKS;
	FRAMETICKS = (unsigned long)(arxtime);
	if(TICKS < 0) {
		return;
	}

	bool key = !GInput->actionPressed(CONTROLS_CUST_MAGICMODE);

	RenderMaterial mat;
	mat.setBlendType(RenderMaterial::Additive);
	
	EERIE_LIGHT * light = lightHandleGet(torchLightHandle);
	
	for(long j = 1; j < 5; j++) {

		TextureContainer * surf;
		switch(j) {
			case 2:  surf = flaretc.lumignon; break;
			case 3:  surf = flaretc.lumignon2; break;
			case 4:  surf = flaretc.plasm; break;
			default: surf = flaretc.shine[shinum]; break;
		}

		mat.setTexture(surf);

		for(size_t i = 0; i < MAX_FLARES; i++) {

			FLARES & flare = magicFlares[i];

			if(!flare.exist || flare.type != j) {
				continue;
			}

			flare.tolive -= float(TICKS * 2);
			if(flare.flags & 1) {
				flare.tolive -= float(TICKS * 4);
			} else if (key) {
				flare.tolive -= float(TICKS * 6);
			}

			float z = (flare.tolive * 0.00025f);
			float s;
			if(flare.type == 1) {
				s = flare.size * 2 * z;
			} else if(flare.type == 4) {
				s = flare.size * 2.f * z + 10.f;
			} else {
				s = flare.size;
			}

			if(flare.tolive <= 0.f || flare.pos.y < -64.f || s < 3.f) {
				removeFlare(flare);
				continue;
			}

			if(flare.type == 1 && z < 0.6f)  {
				z = 0.6f;
			}

			Color3f c = flare.rgb * z;
			flare.tv.color = c.toRGB();
			flare.v.p = flare.tv.p;

			light->rgb = componentwise_max(light->rgb, c);

			if(lightHandleIsValid(flare.dynlight)) {
				EERIE_LIGHT * el = lightHandleGet(flare.dynlight);
				el->pos = flare.v.p;
				el->rgb = c;
			}

			mat.setDepthTest(flare.io != NULL);
			
			if(flare.bDrawBitmap) {
				s *= 2.f * minSizeRatio();
				EERIEAddBitmap(mat, flare.v.p, s, s, surf, Color::fromRGBA(flare.tv.color));
			} else {
				EERIEAddSprite(mat, flare.v.p, s * 0.025f + 1.f,
				               Color::fromRGBA(flare.tv.color), 2.f);
			}

		}
	}

	light->rgb = componentwise_min(light->rgb, Color3f::white);
}
コード例 #22
0
ファイル: OSGMergeGraphOp.cpp プロジェクト: jondo2010/OpenSG
void MergeGraphOp::processTransformations(Node * const node)
{
    MFUnrecChildNodePtr::const_iterator mfit = node->getMFChildren()->begin();
    MFUnrecChildNodePtr::const_iterator mfen = node->getMFChildren()->end  ();
    std::vector<Node *> toAdd;
    std::vector<Node *> toSub;
    
    for ( ; mfit != mfen; ++mfit )
    {
        bool special=isInExcludeList(*mfit);
        bool leaf=isLeaf(*mfit);
        bool empty=true;
        
        //if a transformation:
        if ((*mfit)->getCore()->getType().isDerivedFrom(
                Transform::getClassType()))
        {        
            if (!leaf && !special)
            {
                //try to apply it to children geometries
                //move all "moveable" children one level up
                //if empty after that, delete it
                MFUnrecChildNodePtr::const_iterator it2 = 
                    (*mfit)->getMFChildren()->begin();
                MFUnrecChildNodePtr::const_iterator en2 = 
                    (*mfit)->getMFChildren()->end  ();
                
                for ( ; it2 != en2; ++it2 )
                {
                    if (!isInExcludeList(*it2))
                    {
                        //check if geometry
                        if ((*it2)->getCore()->getType().isDerivedFrom(
                                Geometry::getClassType()))
                        {
                            if(!isLeaf(*it2))
                            {
                                //hmm...bad tree...
                                empty=false;
                            }
                            else
                            {                                
                                //it is a leaf geometry, so apply the transformation
                                Geometry *geo_old = 
                                    dynamic_cast<Geometry *>(
                                        (*it2)->getCore());
                                //GeometryPtr geo = geo_old->clone();
                                GeometryUnrecPtr geo = 
                                    dynamic_pointer_cast<Geometry>(
                                        OSG::deepClone(geo_old, "Material"));

                                Transform *t = 
                                    dynamic_cast<Transform *>(
                                        (*mfit)->getCore());

                                GeoPnt3fProperty *pos  = dynamic_cast<GeoPnt3fProperty *>(geo->getPositions());
                                GeoVec3fProperty *norm = dynamic_cast<GeoVec3fProperty *>(geo->getNormals());
                                GeoColor3fProperty *color = dynamic_cast<GeoColor3fProperty *>(geo->getColors());
                                GeoColor3fProperty *scolor = dynamic_cast<GeoColor3fProperty *>(geo->getSecondaryColors());
                                GeoVec3fProperty *texcoord0 = dynamic_cast<GeoVec3fProperty *>(geo->getTexCoords());
                                GeoVec3fProperty *texcoord1 = dynamic_cast<GeoVec3fProperty *>(geo->getTexCoords1());
                                GeoVec3fProperty *texcoord2 = dynamic_cast<GeoVec3fProperty *>(geo->getTexCoords2());
                                GeoVec3fProperty * texcoord3 = dynamic_cast<GeoVec3fProperty *>(geo->getTexCoords3());

                                Matrix m=t->getMatrix();

                                if(pos!=NULL) 
                                {
                                    for(UInt32 i = 0; i < pos->size(); ++i)
                                    {
                                        Pnt3f p=pos->getValue(i);
                                        m.multFull(p, p);
                                        pos->setValue(p,i);
                                    }
                                }
                                
                                if(norm!=NULL)
                                {
                                    for(UInt32 i = 0; i < norm->size(); ++i)
                                    {
                                        Vec3f n=norm->getValue(i);
                                        m.mult(n, n);
                                        n.normalize();
                                        norm->setValue(n,i);
                                    }
                                }

                                if(color != NULL && _color_is_vector)
                                {
                                    for(UInt32 i = 0; i < color->size(); ++i)
                                    {
                                        Color3f c = color->getValue(i);
                                        Vec3f v;
                                        v.setValue(c.getValuesRGB());
                                        m.mult(v, v);
                                        v.normalize();
                                        c.setValuesRGB(v[0], v[1], v[2]);
                                        color->setValue(c,i);
                                    }
                                }

                                if(scolor != NULL && _secondary_color_is_vector)
                                {
                                    for(UInt32 i = 0; i < scolor->size(); ++i)
                                    {
                                        Color3f c = scolor->getValue(i);
                                        Vec3f v;
                                        v.setValue(c.getValuesRGB());
                                        m.mult(v, v);
                                        v.normalize();
                                        c.setValuesRGB(v[0], v[1], v[2]);
                                        scolor->setValue(c,i);
                                    }
                                }

                                if(texcoord0 != NULL && _texcoord0_is_vector)
                                {
                                    for(UInt32 i = 0; i < texcoord0->size(); ++i)
                                    {
                                        Vec3f v = texcoord0->getValue(i);
                                        m.mult(v, v);
                                        v.normalize();
                                        texcoord0->setValue(v,i);
                                    }
                                }

                                if(texcoord1 != NULL && _texcoord1_is_vector)
                                {
                                    for(UInt32 i = 0; i < texcoord1->size(); ++i)
                                    {
                                        Vec3f v = texcoord1->getValue(i);
                                        m.mult(v, v);
                                        v.normalize();
                                        texcoord1->setValue(v,i);
                                    }
                                }

                                if(texcoord2 != NULL && _texcoord2_is_vector)
                                {
                                    for(UInt32 i = 0; i < texcoord2->size(); ++i)
                                    {
                                        Vec3f v = texcoord2->getValue(i);
                                        m.mult(v, v);
                                        v.normalize();
                                        texcoord2->setValue(v,i);
                                    }
                                }

                                if (texcoord3 != NULL && _texcoord3_is_vector)
                                {
                                    for(UInt32 i = 0; i < texcoord3->size(); i++)
                                    {
                                        Vec3f v = texcoord3->getValue(i);
                                        m.mult(v, v);
                                        v.normalize();
                                        texcoord3->setValue(v,i);
                                    }
                                }
                                (*it2)->setCore(geo);
                                toAdd.push_back(*it2);
                            }
                        } else empty=false;
                    } else empty=false;
                }                
            }
            
            //now check whether we have to remove it
            if ((empty||leaf) && !special)
            {
                toSub.push_back(*mfit);
                continue;
            }
            
            if (leaf && special)
            {
                //what to do?
            }
            if (!leaf && special)
            {
                //what to do?
            }
            continue;
        }
    }
    
    std::vector<Node *>::const_iterator vit = toAdd.begin();
    std::vector<Node *>::const_iterator ven = toAdd.end  ();
    
    for ( ; vit != ven; ++vit )
    {
        node->addChild(*vit);
    }
    
    vit = toSub.begin();
    ven = toSub.end  ();
    
    for ( ; vit != ven; ++vit )
    {
        node->subChild(*vit);
    }
}
コード例 #23
0
ファイル: Color3f.cpp プロジェクト: 4og/guacamole
bool operator==(Color3f const& lhs, Color3f const& rhs) {
  return lhs.r() == rhs.r() &&
         lhs.g() == rhs.g() &&
         lhs.b() == rhs.b();

}
コード例 #24
0
ファイル: ColorTest.cpp プロジェクト: JanDupal/magnum
namespace Magnum { namespace Test {

class ColorTest: public Corrade::TestSuite::Tester {
    public:
        ColorTest();

        void access();

        void fromHue();
        void fromSaturation();
        void fromValue();

        void hue();
        void saturation();
        void value();

        void hsv();
        void hsvOverflow();
        void hsvAlpha();

        void debug();
        void configuration();
};

typedef Magnum::Color3<UnsignedByte> Color3;
typedef Magnum::Color4<UnsignedByte> Color4;
typedef Magnum::Color3<Float> Color3f;
typedef Magnum::Color4<Float> Color4f;

ColorTest::ColorTest() {
    addTests({&ColorTest::access,

              &ColorTest::fromHue,
              &ColorTest::fromSaturation,
              &ColorTest::fromValue,

              &ColorTest::hue,
              &ColorTest::saturation,
              &ColorTest::value,

              &ColorTest::hsv,
              &ColorTest::hsvOverflow,
              &ColorTest::hsvAlpha,

              &ColorTest::debug,
              &ColorTest::configuration});
}

void ColorTest::access() {
    Color3f c3(15, 255, 10);
    const Color3f cc3(15, 255, 10);

    CORRADE_COMPARE(c3.r(), 15);
    CORRADE_COMPARE(c3.g(), 255);
    CORRADE_COMPARE(c3.b(), 10);
    CORRADE_COMPARE(cc3.r(), 15);
    CORRADE_COMPARE(cc3.g(), 255);
    CORRADE_COMPARE(cc3.b(), 10);

    Color4 c4(125, 98, 51, 22);
    const Color4f cc4(125, 98, 51, 22);

    CORRADE_COMPARE(c4.r(), 125);
    CORRADE_COMPARE(c4.g(), 98);
    CORRADE_COMPARE(c4.b(), 51);
    CORRADE_COMPARE(c4.a(), 22);
    CORRADE_COMPARE(cc4.r(), 125);
    CORRADE_COMPARE(cc4.g(), 98);
    CORRADE_COMPARE(cc4.b(), 51);
    CORRADE_COMPARE(cc4.a(), 22);
}

void ColorTest::fromHue() {
    CORRADE_COMPARE(Color3::fromHSV(Deg(27.0f), 1.0f, 1.0f), Color3(255, 114, 0));
    CORRADE_COMPARE(Color3::fromHSV(Deg(86.0f), 1.0f, 1.0f), Color3(144, 255, 0));
    CORRADE_COMPARE(Color3::fromHSV(Deg(134.0f), 1.0f, 1.0f), Color3(0, 255, 59));
    CORRADE_COMPARE(Color3::fromHSV(Deg(191.0f), 1.0f, 1.0f), Color3(0, 208, 255));
    CORRADE_COMPARE(Color3::fromHSV(Deg(269.0f), 1.0f, 1.0f), Color3(123, 0, 255));
    CORRADE_COMPARE(Color3::fromHSV(Deg(317.0f), 1.0f, 1.0f), Color3(255, 0, 182));
}

void ColorTest::hue() {
    CORRADE_COMPARE(Color3(255, 115, 0).hue(), Deg(27.058824f));
    CORRADE_COMPARE(Color3(145, 255, 0).hue(), Deg(85.882353f));
    CORRADE_COMPARE(Color3(0, 255, 60).hue(), Deg(134.11765f));
    CORRADE_COMPARE(Color3(0, 208, 255).hue(), Deg(191.05882f));
    CORRADE_COMPARE(Color3(123, 0, 255).hue(), Deg(268.94117f));
    CORRADE_COMPARE(Color3(255, 0, 183).hue(), Deg(316.94117f));
}

void ColorTest::fromSaturation() {
    CORRADE_COMPARE(Color3::fromHSV(Deg(0.0f), 0.702f, 1.0f), Color3(255, 75, 75));
}

void ColorTest::saturation() {
    CORRADE_COMPARE(Color3(255, 76, 76).saturation(), 0.701961f);
    CORRADE_COMPARE(Color3().saturation(), 0.0f);
}

void ColorTest::fromValue() {
    CORRADE_COMPARE(Color3::fromHSV(Deg(0.0f), 1.0f, 0.522f), Color3(133, 0, 0));
}

void ColorTest::value() {
    CORRADE_COMPARE(Color3(133, 0, 0).value(), 0.521569f);
}

void ColorTest::hsv() {
    CORRADE_COMPARE(Color3::fromHSV(Deg(230.0f), 0.749f, 0.427f), Color3(27, 40, 108));

    Deg hue;
    Float saturation, value;
    std::tie(hue, saturation, value) = Color3(27, 41, 109).toHSV();
    CORRADE_COMPARE(hue, Deg(229.756106f));
    CORRADE_COMPARE(saturation, 0.752294f);
    CORRADE_COMPARE(value, 0.427451f);
}

void ColorTest::hsvOverflow() {
    CORRADE_COMPARE(Color3::fromHSV(Deg(27.0f-360.0f), 1.0f, 1.0f), Color3(255, 114, 0));
    CORRADE_COMPARE(Color3::fromHSV(Deg(86.0f-360.0f), 1.0f, 1.0f), Color3(144, 255, 0));
    CORRADE_COMPARE(Color3::fromHSV(Deg(134.0f-360.0f), 1.0f, 1.0f), Color3(0, 255, 59));
    CORRADE_COMPARE(Color3::fromHSV(Deg(191.0f-360.0f), 1.0f, 1.0f), Color3(0, 208, 255));
    CORRADE_COMPARE(Color3::fromHSV(Deg(269.0f-360.0f), 1.0f, 1.0f), Color3(123, 0, 255));
    CORRADE_COMPARE(Color3::fromHSV(Deg(317.0f-360.0f), 1.0f, 1.0f), Color3(255, 0, 182));

    CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+27.0f), 1.0f, 1.0f), Color3(255, 114, 0));
    CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+86.0f), 1.0f, 1.0f), Color3(144, 255, 0));
    CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+134.0f), 1.0f, 1.0f), Color3(0, 255, 59));
    CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+191.0f), 1.0f, 1.0f), Color3(0, 208, 255));
    CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+269.0f), 1.0f, 1.0f), Color3(123, 0, 255));
    CORRADE_COMPARE(Color3::fromHSV(Deg(360.0f+317.0f), 1.0f, 1.0f), Color3(255, 0, 182));
}

void ColorTest::hsvAlpha() {
    CORRADE_COMPARE(Color4::fromHSV(std::make_tuple(Deg(230.0f), 0.749f, 0.427f), 23), Color4(27, 40, 108, 23));
    CORRADE_COMPARE(Color4::fromHSV(Deg(230.0f), 0.749f, 0.427f, 23), Color4(27, 40, 108, 23));
}

void ColorTest::debug() {
    std::ostringstream o;
    Debug(&o) << Color3f(0.5f, 0.75f, 1.0f);
    CORRADE_COMPARE(o.str(), "Vector(0.5, 0.75, 1)\n");

    o.str({});
    Debug(&o) << Color4f(0.5f, 0.75f, 0.0f, 1.0f);
    CORRADE_COMPARE(o.str(), "Vector(0.5, 0.75, 0, 1)\n");
}

void ColorTest::configuration() {
    Corrade::Utility::Configuration c;

    Color3f color3(0.5f, 0.75f, 1.0f);
    std::string value3("0.5 0.75 1");

    c.setValue("color3", color3);
    CORRADE_COMPARE(c.value("color3"), value3);
    CORRADE_COMPARE(c.value<Color3f>("color3"), color3);

    Color4f color4(0.5f, 0.75f, 0.0f, 1.0f);
    std::string value4("0.5 0.75 0 1");

    c.setValue("color4", color4);
    CORRADE_COMPARE(c.value("color4"), value4);
    CORRADE_COMPARE(c.value<Color4f>("color4"), color4);
}

}}
コード例 #25
0
ファイル: Color3f.cpp プロジェクト: 4og/guacamole
Color3f operator/(Color3f const& lhs, float rhs) {
  return Color3f(lhs.r() / rhs, lhs.g() / rhs, lhs.b() / rhs);
}
コード例 #26
0
ファイル: Color3f.cpp プロジェクト: 4og/guacamole
Color3f operator*(float const& lhs, Color3f rhs) {
  return Color3f(rhs.r() * lhs, rhs.g() * lhs, rhs.b() * lhs);
}
コード例 #27
0
ファイル: bitmap.cpp プロジェクト: valdersoul/NoriV2
float Bitmap::getTotalLuminace(){
    Color3f totalColor = sum();

    float totalLum = totalColor.getLuminance();
    return totalLum;
}
コード例 #28
0
ファイル: path_mis.cpp プロジェクト: valdersoul/NoriV2
    Color3f Li(const Scene *scene, Sampler *sampler, const Ray3f &ray) const {
        /* Find the surface that is visible in the requested direction */
        Intersection its;

        //check if the ray intersects the scene
        if (!scene->rayIntersect(ray, its)) {
            //check if a distant disk light is set
            const Emitter* distantsDisk = scene->getDistantEmitter();
            if(distantsDisk == nullptr ) return Color3f(0.0f);

            //sample the distant disk light
            Vector3f d = ray.d;
            return distantsDisk->sampleL(d);
        }

        //get the Number of lights from the scene
        const  std::vector<Emitter *> lights = scene->getEmitters();
        uint32_t nLights = lights.size();

        Color3f tp(1.0f, 1.0f, 1.0f);
        Color3f L(0.0f, 0.0f, 0.0f);
        Ray3f pathRay(ray.o, ray.d);

        bool deltaFlag = true;

        while(true) {

            if (its.mesh->isEmitter() && deltaFlag) {
                const Emitter* areaLightEM = its.mesh->getEmitter();
                const areaLight* aEM = static_cast<const areaLight *> (areaLightEM);
                L += tp * aEM->sampleL(-pathRay.d, its.shFrame.n, its);
            }

            //Light sampling
            //randomly select a lightsource
            uint32_t var = uint32_t(std::min(sampler->next1D()*nLights, float(nLights) - 1.0f));

            //init the light color
            Color3f Li(0.0f, 0.0f, 0.0f);
            Color3f Ld(1.0f, 1.0f, 1.0f);

            //create a sample for the light
            const BSDF* curBSDF = its.mesh->getBSDF();
            const Point2f lightSample = sampler->next2D();
            VisibilityTester vis;
            Vector3f wo;
            float lightpdf;
            float bsdfpdf;
            Normal3f n = its.shFrame.n;

            deltaFlag = curBSDF->isDeltaBSDF();

            //sample the light

            {
                Li = lights[var]->sampleL(its.p, Epsilon, lightSample , &wo, &lightpdf, &vis);
                lightpdf /= float(nLights);
                //check if the pdf of the sample is greater than 0 and if the color is not black
                if(lightpdf > 0 && Li.maxCoeff() != 0.0f) {
                    //calculate the cosine term wi in my case the vector to the light
                    float cosTerm = std::abs(n.dot(wo));
                    const BSDFQueryRecord queryEM = BSDFQueryRecord(its.toLocal(- pathRay.d), its.toLocal(wo), EMeasure::ESolidAngle, sampler);
                    Color3f f = curBSDF->eval(queryEM);

                    if(f.maxCoeff() > 0.0f && f.minCoeff() >= 0.0f && vis.Unoccluded(scene)) {
                        bsdfpdf = curBSDF->pdf(queryEM);
                        float weight = BalanceHeuristic(float(1), lightpdf, float(1), bsdfpdf);
                        if(curBSDF->isDeltaBSDF())  weight = 1.0f;
                        if(bsdfpdf > 0.0f) {
                            Ld = (weight * f * Li * cosTerm) / lightpdf;
                            L += tp * Ld;
                        } else {
                            //cout << "bsdfpdf = " << bsdfpdf  << endl;
                            //cout << "f = " << f  << endl;
                        }
                    }
                }
            }

            //Material part
            BSDFQueryRecord queryMats = BSDFQueryRecord(its.toLocal(-pathRay.d), Vector3f(0.0f), EMeasure::ESolidAngle, sampler);

            Color3f fi =  curBSDF->sample(queryMats, sampler->next2D());
            bsdfpdf = curBSDF->pdf(queryMats);
            lightpdf = 0.0f;
            if(fi.maxCoeff() > 0.0f && fi.minCoeff() >= 0.0f) {
                if(bsdfpdf > 0.0f) {
                    Ray3f shadowRay(its.p, its.toWorld(queryMats.wo));
                    Intersection lightIsect;

                     if (scene->rayIntersect(shadowRay, lightIsect)) {
                         if(lightIsect.mesh->isEmitter()){
                            const Emitter* areaLightEMcur = lightIsect.mesh->getEmitter();
                            const areaLight* aEMcur = static_cast<const areaLight *> (areaLightEMcur);

                            Li = aEMcur->sampleL(-shadowRay.d, lightIsect.shFrame.n, lightIsect);
                            lightpdf = aEMcur->pdf(its.p, (lightIsect.p - its.p).normalized(), lightIsect.p, Normal3f(lightIsect.shFrame.n));
                         }
                     } else {
                         const Emitter* distantsDisk = scene->getDistantEmitter();
                         if(distantsDisk != nullptr ) {
                             //check if THIS is right!
                             Li = distantsDisk->sampleL(lightIsect.toWorld(queryMats.wo));
                             lightpdf = distantsDisk->pdf(Point3f(0.0f), wo, Point3f(0.0f), Normal3f(0.0f));
                         }
                     }
                     lightpdf /= float(nLights);
                     //calculate the weights
                     float weight = BalanceHeuristic(float(1), bsdfpdf, float(1), lightpdf);


                     //check if the lightcolor is not black
                     if(Li.maxCoeff() > 0.0f  && lightpdf > 0.0f ) {
                         //wo in my case the vector to the light
                         Ld = weight * Li * fi;
                         L += tp * Ld;
                     }
                }



                 tp *= fi;
            } else {
                break;
            }

            wo = its.toWorld(queryMats.wo);
            pathRay = Ray3f(its.p, wo);

            if (!scene->rayIntersect(pathRay, its)) {
                const Emitter* distantsDisk = scene->getDistantEmitter();
                if(distantsDisk != nullptr ) {
                    //sample the distant disk light
                    Vector3f d = pathRay.d;
                    L += tp * distantsDisk->sampleL(d);
                }


                break;
            }

            float maxCoeff = tp.maxCoeff();
            float q = std::min(0.99f, maxCoeff);
            if(q < sampler->next1D()){
                break;
            }
            tp /= q;
        }

        return L;

    }
コード例 #29
0
Action::ResultE ProxyGroup::render(Action *action)
{
    DrawActionBase *da        = dynamic_cast<DrawActionBase *>(action);

    if(getEnabled() == false)
        return Action::Continue;

    if(getState() == NOT_LOADED)
        startLoading();

    if(getState() == LOAD_THREAD_FINISHED)
    {
        if(_loadedRoot != NULL)
        {
            _loadThread = NULL;

            setRoot(_loadedRoot);

            getRoot()->invalidateVolume();
            getRoot()->updateVolume();


            setState(LOADED);

            da->getActNode()->invalidateVolume();
            da->getActNode()->updateVolume    ();
        }
        else
        {
            SWARNING << "failed to load " << getAbsoluteUrl() << std::endl;

            setState(LOAD_ERROR);
        }
    }

    if(getState() == LOADED)
    {
        da->useNodeList();

        if(da->isVisible(getCPtr(getRoot())))
            da->addNode(getRoot());
    }
    else
    {
        if(da->getActNode()->getNChildren() == 0)
        {
            Color3f col;
            col.setValuesRGB(.5,.3,0);            

            dropVolume(da, da->getActNode(), col);
        }
    }

    // thread cleanup
    if(_loadThread && _loadQueue.empty())
    {
        printf("join\n");
        BaseThread::join(_loadThread);
        _loadThread = NULL;
    }

    return Action::Continue;
}
コード例 #30
0
// visibility levels
bool RenderPartition::pushVisibility(Node * const pNode)
{
    if(getFrustumCulling() == false)
        return true;

    FrustumVolume::PlaneSet inplanes = _visibilityStack.back();

    if(inplanes == FrustumVolume::P_ALL)
    {
        _visibilityStack.push_back(inplanes);

        return true;
    }

    Color3f col;
    bool result = true;

    FrustumVolume frustum = _oFrustum;
    BoxVolume     vol     = pNode->getVolume();

    // don't mess with infinite volumes
    if(vol.isInfinite() == false)
    {
        pNode->updateVolume();

        vol = pNode->getVolume();

#if 1
        vol.transform(topMatrix());
#else
    // not quite working
        Matrix m = topMatrix();
        m.invert();

        frustum.transform(m);
#endif
    }

    if(_oDrawEnv.getStatCollector() != NULL)
    {
        _oDrawEnv.getStatCollector()->getElem(statCullTestedNodes)->inc();
    }

    if(intersect(frustum, vol, inplanes) == false)
    {
         result = false;

         col.setValuesRGB(1,0,0);

         if(_oDrawEnv.getStatCollector() != NULL)
         {
             _oDrawEnv.getStatCollector()->getElem(statCulledNodes)->inc();
         }
    }
    else
    {
        if(inplanes == FrustumVolume::P_ALL)
        {
            col.setValuesRGB(0,1,0);
        }
        else
        {
            col.setValuesRGB(0,0,1);
        }
    }

    if(getVolumeDrawing())
    {
        dropVolume(this, pNode, col);
    }

    _visibilityStack.push_back(inplanes);

    return result;
}