Esempio n. 1
0
void Vertex::draw_without_color()
{
	if (!visible_)
	{
		return;
	}

	glNormal3f( normal_(0), normal_(1), normal_(2));
	glVertex3f(position_(0), position_(1), position_(2));
}
Esempio n. 2
0
void  Vertex::draw_without_color( const Matrix44& adjust_matrix)
{
	if (!visible_)
	{
		return;
	}

	glNormal3f( normal_(0), normal_(1), normal_(2));
	Vec4	tmp(position_(0), position_(1), position_(2),1.);
	Vec4	point_to_show = adjust_matrix * tmp;
	glVertex3f( point_to_show(0), point_to_show(1), point_to_show(2) );
}
Esempio n. 3
0
std::string mesh_core::Plane::str(
                const char *pfx,
                const char *sfx,
                int field_width,
                int field_prec) const
{
  Eigen::Vector4d vec(
                    normal_(0),
                    normal_(1),
                    normal_(2),
                    d_);
  return mesh_core::str(vec, pfx, sfx, field_width, field_prec);
}
Esempio n. 4
0
void Vertex::draw_with_label( const Matrix44& adjust_matrix )
{
	if (!visible_)
	{
		return;
	}


	static const IndexType color_step = 47;
	IndexType	label_color = (label_ * color_step) % 255;
	ColorType color = Color_Utility::color_from_table(label_color);


	glColor4f( color(0),color(1),color(2),color(3) );
	glNormal3f( normal_(0), normal_(1), normal_(2));
	Vec4	tmp(position_(0), position_(1), position_(2),1.);
	Vec4	point_to_show = adjust_matrix * tmp;
	glVertex3f( point_to_show(0), point_to_show(1), point_to_show(2) );

}
Esempio n. 5
0
void Vertex::draw_with_label( const Matrix44& adjust_matrix, const Vec3& bias )
{
	if (!visible_)
	{
		return;
	}


	//static const IndexType color_step = 47;
	//IndexType	label_color = (label_ * color_step) % 255;
	//ColorType color = Color_Utility::color_from_table(label_color);
	ColorType color = Color_Utility::span_color_from_table(label_);//可视化标签 7-28 
	//ColorType color = Color_Utility::color_map_one(val_);//可视化曲率

	glColor4f( color(0),color(1),color(2),color(3) );
	glNormal3f( normal_(0), normal_(1), normal_(2));
	Vec4	tmp(position_(0), position_(1), position_(2),1.);
	Vec4	point_to_show = adjust_matrix * tmp;
	glVertex3f( point_to_show(0)+bias(0), point_to_show(1)+bias(1), point_to_show(2)+bias(2) );

}
float dgFastRayTest::PolygonIntersect (const dgVector& normal, const float* const polygon, int32_t strideInBytes, const int32_t* const indexArray, int32_t indexCount) const
{
	HACD_ASSERT (m_p0.m_w == m_p1.m_w);


	#ifndef __USE_DOUBLE_PRECISION__
	float unrealible = float (1.0e10f);
	#endif

	float dist = normal % m_diff;
	if (dist < m_dirError) {

		int32_t stride = int32_t (strideInBytes / sizeof (float));

		dgVector v0 (&polygon[indexArray[indexCount - 1] * stride]);
		dgVector p0v0 (v0 - m_p0);
		float tOut = normal % p0v0;
		// this only work for convex polygons and for single side faces 
		// walk the polygon around the edges and calculate the volume 
		if ((tOut < float (0.0f)) && (tOut > dist)) {
			for (int32_t i = 0; i < indexCount; i ++) {
				int32_t i2 = indexArray[i] * stride;
				dgVector v1 (&polygon[i2]);
				dgVector p0v1 (v1 - m_p0);
				// calculate the volume formed by the line and the edge of the polygon
				float alpha = (m_diff * p0v1) % p0v0;
				// if a least one volume is negative it mean the line cross the polygon outside this edge and do not hit the face
				if (alpha < DG_RAY_TOL_ERROR) {
					#ifdef __USE_DOUBLE_PRECISION__
						return 1.2f;
					#else
						unrealible = alpha;
						break;
					#endif
				}
				p0v0 = p0v1;
			}

			#ifndef __USE_DOUBLE_PRECISION__ 
				if ((unrealible  < float (0.0f)) && (unrealible > (DG_RAY_TOL_ERROR * float (10.0f)))) {
					// the edge is too close to an edge float is not reliable, do the calculation with double
					dgBigVector v0_ (v0);
					dgBigVector m_p0_ (m_p0);
					//dgBigVector m_p1_ (m_p1);
					dgBigVector p0v0_ (v0_ - m_p0_);
					dgBigVector normal_ (normal);
					dgBigVector diff_ (m_diff);
					double tOut_ = normal_ % p0v0_;
					//double dist_ = normal_ % diff_;
					if ((tOut < double (0.0f)) && (tOut > dist)) {
						for (int32_t i = 0; i < indexCount; i ++) {
							int32_t i2 = indexArray[i] * stride;
							dgBigVector v1 (&polygon[i2]);
							dgBigVector p0v1_ (v1 - m_p0_);
							// calculate the volume formed by the line and the edge of the polygon
							double alpha = (diff_ * p0v1_) % p0v0_;
							// if a least one volume is negative it mean the line cross the polygon outside this edge and do not hit the face
							if (alpha < DG_RAY_TOL_ERROR) {
								return 1.2f;
							}
							p0v0_ = p0v1_;
						}

						tOut = float (tOut_);
					}
				}
			#endif

			//the line is to the left of all the polygon edges, 
			//then the intersection is the point we the line intersect the plane of the polygon
			tOut = tOut / dist;
			HACD_ASSERT (tOut >= float (0.0f));
			HACD_ASSERT (tOut <= float (1.0f));
			return tOut;
		}
	}
	return float (1.2f);

}
Esempio n. 7
0
  //--------------------------------------------------------
  //  Constructor
  //         Grab references to ATC and ChargeRegulator 
  //--------------------------------------------------------
  ChargeRegulatorMethod::ChargeRegulatorMethod
    (ChargeRegulator *chargeRegulator, 
     ChargeRegulator::ChargeRegulatorParameters & p)
      : RegulatorShapeFunction(chargeRegulator), 
        chargeRegulator_(chargeRegulator),
        lammpsInterface_(LammpsInterface::instance()),
        rC_(0), rCsq_(0),
        targetValue_(NULL), 
        targetPhi_(p.value), 
        surface_(p.faceset),
        atomGroupBit_(p.groupBit), 
        boundary_(false), 
        depth_(p.depth),
        surfaceType_(p.surfaceType),
        permittivity_(p.permittivity),
        initialized_(false)
  {
    const FE_Mesh * feMesh = atc_->fe_engine()->fe_mesh();
    feMesh->faceset_to_nodeset(surface_,nodes_);
    // assume flat  get normal and primary coord
    PAIR face = *(surface_.begin());
    normal_.reset(nsd_);
    feMesh->face_normal(face,0,normal_);
    DENS_MAT faceCoords;
    feMesh->face_coordinates(face,faceCoords);
    point_.reset(nsd_);
    for (int i=0; i < nsd_; i++) { point_(i) = faceCoords(i,0); }
#ifdef ATC_VERBOSE
    stringstream ss; ss << "point: (" << point_(0) << "," << point_(1) << "," << point_(2) << ") normal: (" << normal_(0) << "," << normal_(1) << "," << normal_(2) << ") depth: " << depth_; 
    lammpsInterface_->print_msg_once(ss.str());
#endif
    sum_.reset(nsd_);
  }
Esempio n. 8
0
File: phong.cpp Progetto: bssrdf/dpt
void SamplePhong(const bool adjoint,
                 const ADFloat *buffer,
                 const ADVector3 &wi,
                 const ADVector3 &normal,
                 const ADVector2 st,
                 const ADVector2 rndParam,
                 const ADFloat uDiscrete,
                 const bool fixDiscrete,
                 ADVector3 &wo,
                 ADVector3 &contrib,
                 ADFloat &cosWo,
                 ADFloat &pdf,
                 ADFloat &revPdf) {
    ADVector3 Kd;
    ADVector3 Ks;
    ADFloat exponent;
    ADFloat KsWeight;
    buffer = Deserialize(buffer, Kd);
    buffer = Deserialize(buffer, Ks);
    buffer = Deserialize(buffer, exponent);
    buffer = Deserialize(buffer, KsWeight);

    ADFloat cosWi = Dot(normal, wi);
    std::vector<CondExprCPtr> ret = CreateCondExprVec(4);
    BeginIf(Gt(cosWi, Float(0.0)), ret);
    { SetCondOutput({normal[0], normal[1], normal[2], cosWi}); }
    BeginElse();
    { SetCondOutput({-normal[0], -normal[1], -normal[2], -cosWi}); }
    EndIf();
    ADVector3 normal_(ret[0], ret[1], ret[2]);
    cosWi = ret[3];
    ADVector3 R = Reflect(wi, normal_);
    ret = CreateCondExprVec(4);
    BeginIf(Gt(uDiscrete, KsWeight), ret);
    {
        ADVector3 localDir = SampleCosHemisphere(rndParam);
        ADVector3 b0;
        ADVector3 b1;
        CoordinateSystem(normal_, b0, b1);
        ADVector3 wo = localDir[0] * b0 + localDir[1] * b1 + localDir[2] * normal_;
        ADFloat factor = (Float(1.0) - KsWeight);
        SetCondOutput({wo[0], wo[1], wo[2], factor});
    }
    BeginElse();
    {
        ADFloat power = Float(1.0) / (exponent + Float(1.0));
        ADFloat cosAlpha = pow(rndParam[1], power);
        // Ugly hack to avoid sqrt(0) which has undefined derivatives...
        ADFloat sinAlpha = sqrt(fmax(Float(1.0) - square(cosAlpha), Float(1e-6)));
        ADFloat phi = c_TWOPI * rndParam[0];
        ADVector3 localDir = ADVector3(sinAlpha * cos(phi), sinAlpha * sin(phi), cosAlpha);
        ADVector3 b0;
        ADVector3 b1;
        CoordinateSystem(R, b0, b1);
        ADVector3 wo = localDir[0] * b0 + localDir[1] * b1 + localDir[2] * R;
        ADFloat factor = KsWeight;
        SetCondOutput({wo[0], wo[1], wo[2], factor});
    }
    EndIf();
    wo = ADVector3(ret[0], ret[1], ret[2]);
    ADFloat factor = ret[3];
    cosWo = Dot(normal_, wo);

    BeginIf(Gt(KsWeight, Float(0.0)), ret);
    {
        ADFloat alpha = fmax(Dot(Reflect(wi, normal_), wo), Float(0.0));
        ADFloat weight = pow(alpha, exponent) * c_INVTWOPI;
        ADFloat expoConst1 = (exponent + Float(1.0));
        ADFloat expoConst2 = (exponent + Float(2.0));
        std::vector<CondExprCPtr> ret = CreateCondExprVec(4);
        BeginIf(Gt(weight, Float(1e-10)), ret);
        {
            ADVector3 specContrib = Ks * (expoConst2 * weight);
            ADFloat specPdf = KsWeight * expoConst1 * weight;
            SetCondOutput({specContrib[0], specContrib[1], specContrib[2], specPdf});
        }
        BeginElse();
        {
            SetCondOutput({Const<ADFloat>(0.0),
                           Const<ADFloat>(0.0),
                           Const<ADFloat>(0.0),
                           Const<ADFloat>(0.0)});
        }
        EndIf();
        ADVector3 specContrib = ADVector3(ret[0], ret[1], ret[2]);
        ADFloat specPdf = ret[3];
        SetCondOutput({specContrib[0], specContrib[1], specContrib[2], specPdf});
    }
    BeginElse();
    {
        SetCondOutput(
            {Const<ADFloat>(0.0), Const<ADFloat>(0.0), Const<ADFloat>(0.0), Const<ADFloat>(0.0)});
    }
    EndIf();
    contrib[0] = ret[0];
    contrib[1] = ret[1];
    contrib[2] = ret[2];
    pdf = ret[3];
    revPdf = ret[3];

    ret = CreateCondExprVec(5);
    BeginIf(Lt(KsWeight, Float(1.0)), ret);
    {
        ADVector3 diffContrib = Kd * Const<ADFloat>(c_INVPI);
        ADFloat tmp = (Float(1.0) - KsWeight) * c_INVPI;
        ADFloat diffPdf = tmp * cosWo;
        ADFloat revDiffPdf = tmp * cosWi;
        SetCondOutput({diffContrib[0], diffContrib[1], diffContrib[2], diffPdf, revDiffPdf});
    }
    BeginElse();
    {
        SetCondOutput({Const<ADFloat>(0.0),
                       Const<ADFloat>(0.0),
                       Const<ADFloat>(0.0),
                       Const<ADFloat>(0.0),
                       Const<ADFloat>(0.0)});
    }
    EndIf();
    contrib[0] += ret[0];
    contrib[1] += ret[1];
    contrib[2] += ret[2];
    pdf += ret[3];
    revPdf += ret[4];

    contrib *= cosWo;
    contrib *= inverse(pdf);
    if (fixDiscrete) {
        contrib *= factor;
    }
}
Esempio n. 9
0
File: phong.cpp Progetto: bssrdf/dpt
void EvaluatePhong(const bool adjoint,
                   const ADFloat *buffer,
                   const ADVector3 &wi,
                   const ADVector3 &normal,
                   const ADVector3 &wo,
                   const ADVector2 st,
                   ADVector3 &contrib,
                   ADFloat &cosWo,
                   ADFloat &pdf,
                   ADFloat &revPdf) {
    ADVector3 Kd;
    ADVector3 Ks;
    ADFloat exponent;
    ADFloat KsWeight;
    buffer = Deserialize(buffer, Kd);
    buffer = Deserialize(buffer, Ks);
    buffer = Deserialize(buffer, exponent);
    buffer = Deserialize(buffer, KsWeight);

    ADFloat cosWi = Dot(normal, wi);
    std::vector<CondExprCPtr> ret = CreateCondExprVec(4);
    BeginIf(Gt(cosWi, Float(0.0)), ret);
    { SetCondOutput({normal[0], normal[1], normal[2], cosWi}); }
    BeginElse();
    { SetCondOutput({-normal[0], -normal[1], -normal[2], -cosWi}); }
    EndIf();
    ADVector3 normal_(ret[0], ret[1], ret[2]);
    cosWi = ret[3];
    cosWo = Dot(normal_, wo);
    ret = CreateCondExprVec(4);
    BeginIf(Gt(KsWeight, Float(0.0)), ret);
    {
        ADFloat alpha = Dot(Reflect(wi, normal_), wo);
        ADFloat weight = pow(alpha, exponent) * c_INVTWOPI;
        std::vector<CondExprCPtr> ret = CreateCondExprVec(4);
        BeginIf(Gt(weight, Float(1e-10)), ret);
        {
            ADFloat expoConst1 = (exponent + Float(1.0));
            ADFloat expoConst2 = (exponent + Float(2.0));
            ADVector3 specContrib = Ks * (expoConst2 * weight);
            ADFloat specPdf = KsWeight * expoConst1 * weight;
            SetCondOutput({specContrib[0], specContrib[1], specContrib[2], specPdf});
        }
        BeginElse();
        {
            SetCondOutput({Const<ADFloat>(0.0),
                           Const<ADFloat>(0.0),
                           Const<ADFloat>(0.0),
                           Const<ADFloat>(0.0)});
        }
        EndIf();
        ADVector3 specContrib = ADVector3(ret[0], ret[1], ret[2]);
        ADFloat specPdf = ret[3];
        SetCondOutput({specContrib[0], specContrib[1], specContrib[2], specPdf});
    }
    BeginElse();
    {
        SetCondOutput(
            {Const<ADFloat>(0.0), Const<ADFloat>(0.0), Const<ADFloat>(0.0), Const<ADFloat>(0.0)});
    }
    EndIf();
    contrib[0] = ret[0];
    contrib[1] = ret[1];
    contrib[2] = ret[2];
    pdf = ret[3];
    revPdf = ret[3];

    ret = CreateCondExprVec(5);
    BeginIf(Lt(KsWeight, Float(1.0)), ret);
    {
        ADVector3 diffContrib = Kd * Const<ADFloat>(c_INVPI);
        ADFloat tmp = (Float(1.0) - KsWeight) * c_INVPI;
        ADFloat diffPdf = tmp * cosWo;
        ADFloat revDiffPdf = tmp * cosWi;
        SetCondOutput({diffContrib[0], diffContrib[1], diffContrib[2], diffPdf, revDiffPdf});
    }
    BeginElse();
    {
        SetCondOutput({Const<ADFloat>(0.0),
                       Const<ADFloat>(0.0),
                       Const<ADFloat>(0.0),
                       Const<ADFloat>(0.0),
                       Const<ADFloat>(0.0)});
    }
    EndIf();
    contrib[0] += ret[0];
    contrib[1] += ret[1];
    contrib[2] += ret[2];
    pdf += ret[3];
    revPdf += ret[4];
    contrib *= cosWo;
}