Ejemplo n.º 1
0
bool LineCircleIntersect(const Line * line, const Circle * circle)
{
	if ((circle->ContainsPoint(line->GetPoint1()) == true) || (circle->ContainsPoint(line->GetPoint2()) == true))
	{
		return true;
	}

	Vector3D v1 = line->GetPoint1();
	Vector3D v2 = line->GetPoint2();
	Vector3D v3 = circle->GetCenter();

	Float r = circle->GetRadius();
	Float a = (v2 - v1).DotProduct(v2 - v1);
	Float b = 2 * (v2 - v1).DotProduct(v1 - v3);
	Float c = v3.DotProduct(v3) + v1.DotProduct(v1) - (2 * v3.DotProduct(v1)) - (r * r);

	Float determinant = (b * b) - (4 * a * c);
	if (determinant >= 0)
	{	
		Float u1 = (-b + Root2(determinant))/(2 * a);
		Float x1 = Smooth(v1.GetX() + (u1 * (v2.GetX() - v1.GetX())));
		Float u2 = (-b - Root2(determinant))/(2 * a);
		Float x2 = Smooth(v1.GetX() + (u2 * (v2.GetX() - v1.GetX())));

		if ((IntervalCheck(x1, v1.GetX(), v2.GetX()) == true) || (IntervalCheck(x2, v1.GetX(), v2.GetX()) == true))
		{
			return true;
		}
	}

	return false;
}
Ejemplo n.º 2
0
float Noise3D::get(float x, float y, float z) const
{
	Vec3f origins[8];
	Vec3f grads[8];

	get_gradients(origins, grads, x, y, z);
	float vals[] = {
		Gradient(origins[0], grads[0], {x, y, z}),
		Gradient(origins[1], grads[1], {x, y, z}),
		Gradient(origins[2], grads[2], {x, y, z}),
		Gradient(origins[3], grads[3], {x, y, z}),
		Gradient(origins[4], grads[4], {x, y, z}),
		Gradient(origins[5], grads[5], {x, y, z}),
		Gradient(origins[6], grads[6], {x, y, z}),
		Gradient(origins[7], grads[7], {x, y, z}),
	};

	float fz = Smooth(z - origins[0].z);
	float vz0 = lerp(vals[0], vals[1], fz);
	float vz1 = lerp(vals[2], vals[3], fz);
	float vz2 = lerp(vals[4], vals[5], fz);
	float vz3 = lerp(vals[6], vals[7], fz);

	float fy = Smooth(y - origins[0].y);
	float vy0 = lerp(vz0, vz1, fy);
	float vy1 = lerp(vz2, vz3, fy);

	float fx = Smooth(x - origins[0].x);
	return lerp(vy0, vy1, fx);
}
Ejemplo n.º 3
0
void sphreport(stream ostr, smxptr sm, string options)
{
  bodyptr *bptr = sm->kd->bptr;
  int i, nupd, nlev[MAXLEV+1], *rprof = sm->rprof;
  real rbsum, rbmin, rbmax, flev[MAXLEV+1], flev4, xi[NRPROF-1];

  nupd = 0;
  for (i = 0; i <= MAXLEV; i++)
    nlev[i] = 0;
  rbsum = 0.0;
  for (i = 0; i < sm->kd->ngas; i++) {
    if (Update(bptr[i])) {
      nupd++;
      nlev[NewLevel(bptr[i])]++;
      rbsum += Smooth(bptr[i]);
      rbmin = (nupd == 1 ? Smooth(bptr[i]) : MIN(rbmin, Smooth(bptr[i])));
      rbmax = (nupd == 1 ? Smooth(bptr[i]) : MAX(rbmin, Smooth(bptr[i])));
    }
  }
  flev4 = 0.0;
  for (i = 0; i <= MAXLEV; i++) {
    flev[i] = 100.0 * ((real) nlev[i]) / ((real) nupd);
    if (i >= 4)
      flev4 += flev[i];
  }
  fprintf(ostr, "\n%9s %9s %9s %9s %29s %9s\n",
	  "log hmin", "log havg", "log hmax", "freqavg",
	  "timestep level distribution", "CPUsph"); 
  fprintf(ostr,
	  "%9.4f %9.4f %9.4f %9.2f %5.1f %5.1f %5.1f %5.1f %5.1f %9.3f\n",
	  rlog10(rbmin), rlog10(rbsum / nupd), rlog10(rbmax),
	  sm->freqsum / nupd, flev[0], flev[1], flev[2], flev[3], flev4,
	  cputime() - sm->cpustart);
  if (scanopt(options, "corrfunc")) {
    for (i = 0; i <= NRPROF - 2; i++)
      xi[i] = -1 + rpow(8.0, i/2.0) * (rprof[i] - rprof[i+1]) /
	((1 - rsqrt(0.125)) * rprof[0]);
    fprintf(ostr, "\n     ");
    for (i = NRPROF - 2; i >= 0; i--)
      fprintf(ostr, "   xi%d", i);
    fprintf(ostr, "\n     ");
    for (i = NRPROF - 2; i >= 0; i--)
      fprintf(ostr, "%6.2f", xi[i]);
    fprintf(ostr, "\n");
  }	
  if (scanopt(options, "levelhist")) {
    fprintf(ostr, "\n     ");
    for (i = 0; i <= MAXLEV; i++)
      if (nlev[i] != 0)
	fprintf(ostr, i<10 ? "  lev%d" : " lev%d", i);
    fprintf(ostr, "\n     ");
    for (i = 0; i <= MAXLEV; i++)
      if (nlev[i] != 0)
	fprintf(ostr, "%6d", nlev[i]);
    fprintf(ostr, "\n");
  }	
  fflush(ostr);
}
Ejemplo n.º 4
0
bool LineSegment::ContainsPoint(const Point3D& point) const
{
	Rect rect(p1, p2);
	if (rect.ContainsPoint(point) == true)
	{
		Float slope = CalculateSlope(p1, point);
		return (Smooth(slope) == Smooth(GetSlope()));
	}
	return false;
}
Ejemplo n.º 5
0
cStructGenRavines::cRavine::cRavine(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, int a_Size, cNoise & a_Noise) :
	super(a_GridX, a_GridZ, a_OriginX, a_OriginZ)
{
	// Calculate the ravine shape-defining points:
	GenerateBaseDefPoints(a_OriginX, a_OriginZ, a_Size, a_Noise);

	// Smooth the ravine. Two passes are needed:
	Smooth();
	Smooth();

	// Linearly interpolate the neighbors so that they're close enough together:
	FinishLinear();
}
Ejemplo n.º 6
0
void DrivenFeature::Update(float now, FaceAPIData* data, float adaptiveSmooth)
{
	bool dataExists = 
			data != NULL && 
			data->h_confidence > 0 && 
			data->h_data.find(m_fapiIndex) != data->h_data.end();

	float value;

	if(!dataExists)
	{
		value = FadeOut(now);
	}
	else
	{
		value = data->h_data[m_fapiIndex] * (m_reverse ? -1 : 1);
		Neutralise(value, data->h_frameNum, data->h_frameDuration);
		Smooth(value, now, adaptiveSmooth);
		Scale(value);
		value = FadeIn(value, now);
	}

	if(m_isPose)
	{
		m_actor->SetPoseParameter(m_poseIndex, RAD_TO_DEG(value));
	}
	else
	{
		value = clamp(value, 0, 1);
		for(int i = 0; i < m_flexors.size(); i++)
			m_actor->SetFlexWeight(m_flexors[i], value);
	}
}
Ejemplo n.º 7
0
bool TexSheet::Reload()
{
    if (loaded == true) {
        if(VIDEO_DEBUG)
            IF_PRINT_WARNING(VIDEO_DEBUG) << "attempted to load an already loaded texture sheet" << std::endl;
        return false;
    }

    // Create new OpenGL texture.
    GLuint id = TextureManager->_CreateBlankGLTexture(width, height);

    if (id == INVALID_TEXTURE_ID) {
        PRINT_ERROR << "call to TextureController::_CreateBlankGLTexture() failed" << std::endl;
        return false;
    }

    tex_id = id;

    // Restore texture smoothing if applied.
    bool was_smoothed = smoothed;
    smoothed = false;
    Smooth(was_smoothed);

    // Reload all of the images that belong to this texture
    if(TextureManager->_ReloadImagesToSheet(this) == false) {
        PRINT_ERROR << "call to TextureController::_ReloadImagesToSheet() failed" << std::endl;
        return false;
    }

    loaded = true;
    return true;
}
Ejemplo n.º 8
0
bool Interpolator::LinearQuaternion(FlKeyCode keycode, FlKeyGroup* g1, FlKeyGroup* g2, double t, Quaternion &qval)
{
	qval = Quaternion(0, 0, 0, 1);
	if (!g1 || !g2) return false;
	FlKey *key1 = SearchKey(keycode, g1);
	FlKey *key2 = SearchKey(keycode, g2);
	if (!key1 || !key2) return false;
	if (key1->GetType()!=FLKEY_TYPE_QUATER ||
		key2->GetType()!=FLKEY_TYPE_QUATER)
		return false;
	double t1, t2;
	Quaternion q1, q2;
	q1 = ((FlKeyQuaternion*)key1)->GetValue();
	q2 = ((FlKeyQuaternion*)key2)->GetValue();
	t1 = g1->t;
	t2 = g2->t;
	if (t1 == t2)
	{
		qval = q1;
		return true;
	}
	double st = Smooth((t-t1)/(t2-t1), g1->type==1, g2->type==1);
	qval = Slerp(q1, q2, st);
	return true;
}
Ejemplo n.º 9
0
cCaveTunnel::cCaveTunnel(
	int a_BlockStartX, int a_BlockStartY, int a_BlockStartZ, int a_StartRadius,
	int a_BlockEndX,   int a_BlockEndY,   int a_BlockEndZ,   int a_EndRadius,
	cNoise & a_Noise
)
{
	m_Points.push_back(cCaveDefPoint(a_BlockStartX, a_BlockStartY, a_BlockStartZ, a_StartRadius));
	m_Points.push_back(cCaveDefPoint(a_BlockEndX,   a_BlockEndY,   a_BlockEndZ,   a_EndRadius));

	if ((a_BlockStartY <= 0) && (a_BlockEndY <= 0))
	{
		// Don't bother detailing this cave, it's under the world anyway
		m_MinBlockX = m_MaxBlockX = 0;
		m_MinBlockY = m_MaxBlockY = -1;
		m_MinBlockZ = m_MaxBlockZ = 0;
		return;
	}

	Randomize(a_Noise);
	Smooth();

	// We know that the linear finishing won't affect the bounding box, so let's calculate it now, as we have less data:
	CalcBoundingBox();

	FinishLinear();
}
Ejemplo n.º 10
0
void K1999::CalcRaceLine()
{
	const unsigned int stepsize = 128;
	
	//abort if the track isn't long enough
	if (tx.size() < stepsize)
		return;
	
 //
 // Smoothing loop
 //
 for (int Step = stepsize; (Step /= 2) > 0;)
 {
  for (int i = Iterations * int(sqrt(float(Step))); --i >= 0;)
   Smooth(Step);
  Interpolate(Step);
 }
 
 //
 // Compute curvature along the path
 //
 for (int i = Divs; --i >= 0;)
 {
  int next = (i + 1) % Divs;
  int prev = (i - 1 + Divs) % Divs;

  double rInverse = GetRInverse(prev, tx[i], ty[i], next);
  tRInverse[i] = rInverse;
 }

#ifdef DRAWPATH
 std::ofstream ofs("k1999.path");
 DrawPath(ofs);
#endif
} 
Ejemplo n.º 11
0
void ac::ImageReverseSubFilter(cv::Mat &frame) {
    if(blend_set == false || subfilter == -1 || ac::draw_strings[subfilter] == "ImageReverseSubFilter")
        return;
    
    cv::Mat reimage;
    cv::resize(blend_image, reimage, frame.size());
    cv::Mat all_frames[3];
    cv::flip(frame, all_frames[0], -1);
    cv::flip(frame, all_frames[1], 0);
    cv::flip(frame, all_frames[2], 1);
    cv::Mat copy1 = frame.clone(), copy2 = frame.clone();
    for(int z = 0; z < copy1.rows; ++z) {
        for(int i = 0; i < copy1.cols; ++i){
            cv::Vec3b &pixel = copy1.at<cv::Vec3b>(z, i);
            cv::Vec3b pix[4];
            for(int j = 0; j < 3; ++j) {
                pix[j] = all_frames[j].at<cv::Vec3b>(z, i);
            }
            for(int j = 0; j < 3; ++j) {
                pixel[j] = pix[0][j] ^ pix[1][j] ^ pix[2][j] ^ pixel[j];
            }
        }
    }
    static MatrixCollection<8> collection;
    Smooth(copy1, &collection);
    CallFilter(subfilter, reimage);
    Xor(reimage, copy1);
    AlphaBlend(reimage, copy2, frame, 0.5);
    DarkenFilter(frame);
    MedianBlend(frame);
}
Ejemplo n.º 12
0
void ac::InterSmoothSubFilter(cv::Mat &frame) {
    if(subfilter == -1 || ac::draw_strings[subfilter] == "InterSmoothSubFilter")
        return;
    static MatrixCollection<8> collection;
    cv::Mat frame_copy = frame.clone();
    CallFilter(subfilter, frame_copy);
    int index = 0;
    static double alpha = 1.0, alpha_max = 4.0;
    for(int z = 0; z < frame.rows; ++z) {
        for(int i = 0; i < frame.cols; ++i) {
            cv::Vec3b &pixel = frame.at<cv::Vec3b>(z, i);
            cv::Vec3b pix = frame_copy.at<cv::Vec3b>(z, i);
            switch(index) {
                case 0:
                    for(int j = 0; j < 3; ++j)
                        pixel[j] = static_cast<unsigned char>(pixel[j]*(alpha+1))^pix[j];
                    break;
                case 1:
                    pixel = pix;
                    break;
            }
        }
        ++index;
        if(index > 1)
            index = 0;
    }
    static int dir = 1;
    procPos(dir, alpha, alpha_max, 4.1, 0.05);
    collection.shiftFrames(frame);
    Smooth(frame, &collection);
    AddInvert(frame);
}
Ejemplo n.º 13
0
void Terrain::Init(ID3D11Device* device, ID3D11DeviceContext* dc, const InitInfo& initInfo)
{
	mInfo = initInfo;

	// Divide heightmap into patches such that each patch has CellsPerPatch.
	mNumPatchVertRows = ((mInfo.HeightmapHeight-1) / CellsPerPatch) + 1;
	mNumPatchVertCols = ((mInfo.HeightmapWidth-1) / CellsPerPatch) + 1;

	mNumPatchVertices  = mNumPatchVertRows*mNumPatchVertCols;
	mNumPatchQuadFaces = (mNumPatchVertRows-1)*(mNumPatchVertCols-1);

	LoadHeightmap();
	Smooth();
	CalcAllPatchBoundsY();

	BuildQuadPatchVB(device);
	BuildQuadPatchIB(device);
	BuildHeightmapSRV(device);

	std::vector<std::wstring> layerFilenames;
	layerFilenames.push_back(mInfo.LayerMapFilename0);
	layerFilenames.push_back(mInfo.LayerMapFilename1);
	layerFilenames.push_back(mInfo.LayerMapFilename2);
	layerFilenames.push_back(mInfo.LayerMapFilename3);
	layerFilenames.push_back(mInfo.LayerMapFilename4);
	mLayerMapArraySRV = d3dHelper::CreateTexture2DArraySRV(device, dc, layerFilenames);

	HR(D3DX11CreateShaderResourceViewFromFileW(device, 
		mInfo.BlendMapFilename.c_str(), 0, 0, &mBlendMapSRV, 0));

}
Ejemplo n.º 14
0
void ac::SmoothTrailsBlend(cv::Mat &frame) {
    static MatrixCollection<16> collection;
    cv::Mat copyf = frame.clone();
    cv::Mat copyi = frame.clone();
    Smooth(copyf, &collection);
    AlphaBlend(copyf, copyi, frame, 0.5);
    AddInvert(frame);
}
Ejemplo n.º 15
0
float Noise2D::get(float x, float y) const
{
	Vec2f origins[4];
	Vec2f grads[4];

	get_gradients(origins, grads, x, y);
	float vals[] = {
		Gradient(origins[0], grads[0], {x, y}),
		Gradient(origins[1], grads[1], {x, y}),
		Gradient(origins[2], grads[2], {x, y}),
		Gradient(origins[3], grads[3], {x, y}),
	};

	float fx = Smooth(x - origins[0].x);
	float vx0 = lerp(vals[0], vals[1], fx);
	float vx1 = lerp(vals[2], vals[3], fx);
	float fy = Smooth(y - origins[0].y);
	return lerp(vx0, vx1, fy);
}
Ejemplo n.º 16
0
TexSheet::TexSheet(uint32 sheet_width, uint32 sheet_height, GLuint sheet_id, TexSheetType sheet_type, bool sheet_static) :
    width(sheet_width),
    height(sheet_height),
    tex_id(sheet_id),
    type(sheet_type),
    is_static(sheet_static),
    smoothed(false),
    loaded(true)
{
    Smooth();
}
Ejemplo n.º 17
0
/*
 * Synthesis using pitch marks.
 *
 * Derived instances of FBAproc should override method
 * SynthesizePM() to add the desired functionality
 *
 * @return O_K if successfull, NOT_EXEC otherwise
 */
INT16 CGEN_VPROTECTED CFBAproc::SynthesizeUsingPM(data *idFea, data *idPm, data *idSyn) {
  CData   *idExcite    = NULL;
  FLOAT64 *excitation  = NULL;
  FLOAT64 *synthesis   = NULL;
  INT32    nSamples    = 0;
  INT16    nPer        = 0;
  INT32    nCompVuv    = idFea->FindComp("v/uv");
  INT16    nCompFea    = idFea->GetNNumericComps() - (nCompVuv >= 0 ? 1 : 0);
  INT32    iRecFea     = 0;
  INT32    nRecFea     = 0;

  AlignFramesToPitch(idPm, idFea, idFea);

  nRecFea = idFea->GetNRecs();

  if(m_bSynEnhancement) {
    for(iRecFea = 0; iRecFea < nRecFea; iRecFea++) {
      FeaEnhancement((FLOAT64*)idFea->XAddr(iRecFea,0), nCompFea);
    }
  }

  Smooth(idFea, idPm, idFea);

  // Generate modulated excitation
  ICREATEEX(CData,idExcite,"~idExcite",NULL);
  DLPASSERT(O_K==ModEx(idPm,idExcite));
  DLPASSERT(!idExcite->IsEmpty());

  nSamples = idExcite->GetNRecs();

  idSyn->Reset();
  idSyn->AddComp("syn", T_DOUBLE);
  idSyn->Allocate(nSamples);

  excitation = (FLOAT64*)idExcite->XAddr(0, 0);
  synthesis = (FLOAT64*)idSyn->XAddr(0, 0);

  for(INT32 currSample = 0, currPer = 0; (currSample < nSamples) && (currPer < idFea->GetNRecs()); currSample += nPer, currPer++) {
    nPer = (INT16)idPm->Dfetch(currPer,0);

    if(SynthesizeFrame((FLOAT64*)idFea->XAddr(currPer,0), nCompFea, excitation+currSample, nPer, synthesis+currSample) != O_K) {
      IDESTROY(idExcite);
      return IERROR(this,FBA_SYNTHESISE, currPer, 0,0);
    }
  }

  IDESTROY(idExcite);

  if (m_nMinLog != 0.0) for (INT32 i=0; i<idSyn->GetNRecs(); i++) *((FLOAT64*)idSyn->XAddr(0, 0)+i) *= exp(m_nMinLog);

  return O_K;
}
Ejemplo n.º 18
0
void generateRaceLine(tTrack *pTrack, const double lSideDistExt, const double lSideDistInt)
{
	SideDistExt = lSideDistExt;
	SideDistInt = lSideDistInt;
	
	SplitTrack(pTrack);

	for (int Step = 128; (Step /= 2) > 0;) {
		for (int i = 100 * int(sqrt((double)Step)); --i >= 0;) {
			Smooth(Step);
		}
		Interpolate(Step);
	}
}
Ejemplo n.º 19
0
void CAMCode<B,T,D>::CalcMom (TSpecie *sp, ScaField &dn, VecField &blk)
{
  dn = T(0);
  blk = T(0);

  BilinearWeightCache<T,D> cache;
  for (int pid=0; pid<sp->GetSize(); ++pid)
  {
    const TParticle &pcle = sp->Get (pid);

    FillCache (pcle.pos, cache);
    cache.ipos += 1;
    CartStencil::BilinearWeightAdd (dn, cache, T(1));
    CartStencil::BilinearWeightAdd (blk, cache, pcle.vel);
  }

  dn.Sync ();
  blk.Sync ();
  if (_momsmooth && (_time.Iter() % _momsmooth == 0))
  {
    Smooth (dn);
    Smooth (blk);
  }
}
Ejemplo n.º 20
0
void ac::StoredFramesAlphaBlend_SubFilter(cv::Mat &frame) {
    if(subfilter == -1 || ac::draw_strings[subfilter] == "StoredFramesAlphaBlend_SubFilter")
        return;
    static MatrixCollection<8> collection;
    static double alpha = 1.0, alpha_max = 4.0;
    cv::Mat frame_copy = frame.clone();
    CallFilter(subfilter, frame_copy);
    cv::Mat fcopy = frame.clone();
    AlphaBlend(fcopy, frame_copy, frame, alpha);
    collection.shiftFrames(frame);
    Smooth(frame, &collection);
    static int dir = 1;
    procPos(dir, alpha, alpha_max, 4.1, 0.05);
    AddInvert(frame);
}
Ejemplo n.º 21
0
void ac::ImageCollectionSubFilter(cv::Mat &frame) {
    if(blend_set == false || subfilter == -1 || ac::draw_strings[subfilter] == "ImageBlendXorSubFilter")
        return;
    static double alpha = 1.0, alpha_max = 4.0;
    static int dir = 1;
    cv::Mat frame_copy1 = frame.clone();
    cv::Mat frame_copy2 = frame.clone();
    ExactImage(frame_copy1);
    AlphaBlend(frame_copy1, frame_copy2, frame, alpha);
    CallFilter(subfilter, frame);
    static MatrixCollection<8> collection;
    collection.shiftFrames(frame);
    Smooth(frame, &collection);
    procPos(dir, alpha, alpha_max, 4.1, 0.05);
    AddInvert(frame);
}
Ejemplo n.º 22
0
void ac::SetColormap(cv::Mat &frame) {
    static int index = 2;
    static int counter = 0;
    static MatrixCollection<16> collection;
    int fps = static_cast<int>(ac::fps);
    cv::Mat copy1 = frame.clone(), copy2 = frame.clone();
    ++counter;
    setColorMap(index, copy2);
    Smooth(copy2, &collection);
    if((counter%fps) == 0) {
        ++index;
        if(index > 10)
            index = 2;
    }
    AlphaBlendDouble(copy1, copy2, frame, 0.5, 0.5);
    AddInvert(frame);
}
Ejemplo n.º 23
0
void Terrain::Generate(Operation mode, int iterations)
{
	for(int i = 0; i < iterations; i++)
	{
		switch (mode)
		{
			case FAULT:
				FaultAlgorithm();
				break;
			case SMOOTH:
				Smooth(smooth_factor);
				break;
			case CIRCLES:
				CirclesAlgorithm();
			break;
		}
	}

}
Ejemplo n.º 24
0
void SmoothImage(int **im,int **dest,int w,int h,int size,double theta){

int grey,i,j;
double **dest1;
double **im1;
	cout<<"sm 01"<<flush<<endl;
 dest1=new double* [w];
 im1=new double* [w];
 for(i=0;i<w;i++){
   dest1[i]=new double[h];
   im1[i]=new double[h];
 }
	cout<<"sm 01"<<flush<<endl;
for (i=0;i<w;i++){
  for(j=0;j<h;j++){
    im1[i][j]=im[i][j];
   }
}
	cout<<"sm 01"<<flush<<endl;
Smooth(im1,dest1,w,h,size,theta);
cout<<"sm 01"<<flush<<endl;
for(i=0;i<w;i++){
  for(j=0;j<h;j++){
    grey=(int)dest1[i][j];
    if(grey>255)grey=255;
    if(grey<0)grey=0;
    dest[i][j]=grey;
  }
}
	cout<<"sm 01"<<flush<<endl;
 for(i=0;i<w;i++){
   delete(im1[i]);
   delete(dest1[i]);
 }cout<<"sm 01"<<flush<<endl;
 delete(im1);
 delete(dest1);
}
Ejemplo n.º 25
0
bool Interpolator::LinearDouble(FlKeyCode keycode, FlKeyGroup* g1, FlKeyGroup* g2, double t, double &dval)
{
	dval = 0.0;
	if (!g1 || !g2) return false;
	FlKey *key1 = SearchKey(keycode, g1);
	FlKey *key2 = SearchKey(keycode, g2);
	if (!key1 || !key2) return false;
	if (key1->GetType()!=FLKEY_TYPE_DOUBLE ||
		key2->GetType()!=FLKEY_TYPE_DOUBLE)
		return false;
	double v1, v2, t1, t2;
	v1 = ((FlKeyDouble*)key1)->GetValue();
	v2 = ((FlKeyDouble*)key2)->GetValue();
	t1 = g1->t;
	t2 = g2->t;
	if (t1 == t2)
	{
		dval = v1;
		return true;
	}
	double st = Smooth((t-t1)/(t2-t1), g1->type==1, g2->type==1);
	dval = v1 + st * (v2-v1);
	return true;
}
Ejemplo n.º 26
0
    MagicDGP::LightMesh3D* PoissonReconstruction::SurfaceTrimmer(int argc , char* argv[], std::vector< PlyValueVertex< float > >& vertices, std::vector< std::vector< int > >& polygons)
    {
        cmdLineString In( "in" ) , Out( "out" );
        cmdLineInt Smooth( "smooth" , 5 );
        cmdLineFloat Trim( "trim" ) , IslandAreaRatio( "aRatio" , 0.001f );
        cmdLineFloatArray< 2 > ColorRange( "color" );
        cmdLineReadable PolygonMesh( "polygonMesh" );

        cmdLineReadable* params[] =
        {
            &In , &Out , &Trim , &PolygonMesh , &ColorRange , &Smooth , &IslandAreaRatio
        };

        int paramNum = sizeof(params)/sizeof(cmdLineReadable*);
        cmdLineParse( argc , argv, paramNum , params , 0 );

        float min , max;
        //std::vector< PlyValueVertex< float > > vertices;
        //std::vector< std::vector< int > > polygons;

        //int ft , commentNum = paramNum+2;
        //char** comments;
        //bool readFlags[ PlyValueVertex< float >::Components ];
        //PlyReadPolygons( In.value , vertices , polygons , PlyValueVertex< float >::Properties , PlyValueVertex< float >::Components , ft , &comments , &commentNum , readFlags );
        //if( !readFlags[3] ){ fprintf( stderr , "[ERROR] vertices do not have value flag\n" ) ; return EXIT_FAILURE; }

        for( int i=0 ; i<Smooth.value ; i++ ) SmoothValues( vertices , polygons );

        min = max = vertices[0].value;
        for( size_t i=0 ; i<vertices.size() ; i++ ) min = std::min< float >( min , vertices[i].value ) , max = std::max< float >( max , vertices[i].value );
        printf( "Value Range: [%f,%f]\n" , min , max );


        if( Trim.set )
        {
            hash_map< long long , int > vertexTable;
            std::vector< std::vector< int > > ltPolygons , gtPolygons;
            std::vector< bool > ltFlags , gtFlags;

            /*for( int i=0 ; i<paramNum+2 ; i++ ) comments[i+commentNum]=new char[1024];
            sprintf( comments[commentNum++] , "Running Surface Trimmer (V5)" );
            if(              In.set ) sprintf(comments[commentNum++],"\t--%s %s" , In.name , In.value );
            if(             Out.set ) sprintf(comments[commentNum++],"\t--%s %s" , Out.name , Out.value );
            if(            Trim.set ) sprintf(comments[commentNum++],"\t--%s %f" , Trim.name , Trim.value );
            if(          Smooth.set ) sprintf(comments[commentNum++],"\t--%s %d" , Smooth.name , Smooth.value );
            if( IslandAreaRatio.set ) sprintf(comments[commentNum++],"\t--%s %f" , IslandAreaRatio.name , IslandAreaRatio.value );
            if(     PolygonMesh.set ) sprintf(comments[commentNum++],"\t--%s" , PolygonMesh.name );*/

            double t=Time();
            for( size_t i=0 ; i<polygons.size() ; i++ ) SplitPolygon( polygons[i] , vertices , &ltPolygons , &gtPolygons , &ltFlags , &gtFlags , vertexTable , Trim.value );
            if( IslandAreaRatio.value>0 )
            {
                std::vector< std::vector< int > > _ltPolygons , _gtPolygons;
                std::vector< std::vector< int > > ltComponents , gtComponents;
                SetConnectedComponents( ltPolygons , ltComponents );
                SetConnectedComponents( gtPolygons , gtComponents );
                std::vector< double > ltAreas( ltComponents.size() , 0. ) , gtAreas( gtComponents.size() , 0. );
                std::vector< bool > ltComponentFlags( ltComponents.size() , false ) , gtComponentFlags( gtComponents.size() , false );
                double area = 0.;
                for( size_t i=0 ; i<ltComponents.size() ; i++ )
                {
                    for( size_t j=0 ; j<ltComponents[i].size() ; j++ )
                    {
                        ltAreas[i] += PolygonArea( vertices , ltPolygons[ ltComponents[i][j] ] );
                        ltComponentFlags[i] = ( ltComponentFlags[i] || ltFlags[ ltComponents[i][j] ] );
                    }
                    area += ltAreas[i];
                }
                for( size_t i=0 ; i<gtComponents.size() ; i++ )
                {
                    for( size_t j=0 ; j<gtComponents[i].size() ; j++ )
                    {
                        gtAreas[i] += PolygonArea( vertices , gtPolygons[ gtComponents[i][j] ] );
                        gtComponentFlags[i] = ( gtComponentFlags[i] || gtFlags[ gtComponents[i][j] ] );
                    }
                    area += gtAreas[i];
                }
                for( size_t i=0 ; i<ltComponents.size() ; i++ )
                {
                    if( ltAreas[i]<area*IslandAreaRatio.value && ltComponentFlags[i] ) for( size_t j=0 ; j<ltComponents[i].size() ; j++ ) _gtPolygons.push_back( ltPolygons[ ltComponents[i][j] ] );
                    else                                                               for( size_t j=0 ; j<ltComponents[i].size() ; j++ ) _ltPolygons.push_back( ltPolygons[ ltComponents[i][j] ] );
                }
                for( size_t i=0 ; i<gtComponents.size() ; i++ )
                {
                    if( gtAreas[i]<area*IslandAreaRatio.value && gtComponentFlags[i] ) for( size_t j=0 ; j<gtComponents[i].size() ; j++ ) _ltPolygons.push_back( gtPolygons[ gtComponents[i][j] ] );
                    else                                                               for( size_t j=0 ; j<gtComponents[i].size() ; j++ ) _gtPolygons.push_back( gtPolygons[ gtComponents[i][j] ] );
                }
                ltPolygons = _ltPolygons , gtPolygons = _gtPolygons;
            }
            if( !PolygonMesh.set )
            {
                {
                    std::vector< std::vector< int > > polys = ltPolygons;
                    Triangulate( vertices , ltPolygons , polys ) , ltPolygons = polys;
                }
                {
                    std::vector< std::vector< int > > polys = gtPolygons;
                    Triangulate( vertices , gtPolygons , polys ) , gtPolygons = polys;
                }
            }

            RemoveHangingVertices( vertices , gtPolygons );

            MagicDGP::LightMesh3D* pExportMesh = new MagicDGP::LightMesh3D;
            for (int pIndex = 0; pIndex < vertices.size(); pIndex++)
            {
                PlyValueVertex< float > vert = vertices.at(pIndex);
                MagicMath::Vector3 vertPos(vert.point[0], vert.point[1], vert.point[2]);
                pExportMesh->InsertVertex(vertPos);
            }
            for (int pIndex = 0; pIndex < gtPolygons.size(); pIndex++)
            {
                MagicDGP::FaceIndex faceIdx;
                for (int k = 0; k < 3; k++)
                {
                    faceIdx.mIndex[k] = gtPolygons.at(pIndex).at(k);
                }
                pExportMesh->InsertFace(faceIdx);
            }
            pExportMesh->UpdateNormal();
            
            return pExportMesh;
        }
        else
        {
            //if( ColorRange.set ) min = ColorRange.values[0] , max = ColorRange.values[1];
            //std::vector< PlyColorVertex< float > > outVertices;
            //ColorVertices( vertices , outVertices , min , max );
            ////if( Out.set ) PlyWritePolygons( Out.value , outVertices , polygons , PlyColorVertex< float >::Properties , PlyColorVertex< float >::Components , ft , comments , commentNum );
            //if( Out.set ) PlyWritePolygons( Out.value , outVertices , polygons , PlyColorVertex< float >::Properties , PlyColorVertex< float >::Components , 1 , NULL , 0 );
        }

        return NULL;
    }
Ejemplo n.º 27
0
void print_data(bodyptr btab, int nbody, real tnow, string *fields,
		string ifmt, string rfmt)
{
    bodyptr bp;

    for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
	if (set_member(fields, TimeTag))
	    printf(rfmt, tnow);
	if (set_member(fields, MassTag))
	    printf(rfmt, Mass(bp));
	if (set_member(fields, PosTag)) {
	    printf(rfmt, Pos(bp)[0]);
	    printf(rfmt, Pos(bp)[1]);
	    printf(rfmt, Pos(bp)[2]);
	}
	if (set_member(fields, VelTag)) {
	    printf(rfmt, Vel(bp)[0]);
	    printf(rfmt, Vel(bp)[1]);
	    printf(rfmt, Vel(bp)[2]);
	}
	if (set_member(fields, AccTag)) {
	    printf(rfmt, Acc(bp)[0]);
	    printf(rfmt, Acc(bp)[1]);
	    printf(rfmt, Acc(bp)[2]);
	}
	if (set_member(fields, PhiTag))
	    printf(rfmt, Phi(bp));
	if (set_member(fields, SmoothTag))
	    printf(rfmt, Smooth(bp));
	if (set_member(fields, RhoTag))
	    printf(rfmt, Rho(bp));
	if (set_member(fields, EntFuncTag))
	    printf(rfmt, EntFunc(bp));
	if (set_member(fields, UinternTag))
	    printf(rfmt, Uintern(bp));
	if (set_member(fields, UdotIntTag))
	    printf(rfmt, UdotInt(bp));
        if (set_member(fields, UdotRadTag))
	    printf(rfmt, UdotRad(bp));
        if (set_member(fields, UdotVisTag))
	    printf(rfmt, UdotVis(bp));
	if (set_member(fields, TauTag))
	    printf(rfmt, Tau(bp));
	if (set_member(fields, BirthTag))
	    printf(rfmt, Birth(bp));
	if (set_member(fields, DeathTag))
	    printf(rfmt, Death(bp));
	if (set_member(fields, TypeTag))
	  printf(ifmt, (int) Type(bp));
	if (set_member(fields, KeyTag))
	    printf(ifmt, Key(bp));
	if (set_member(fields, AuxTag))
	    printf(rfmt, Aux(bp));
	if (set_member(fields, AuxVecTag)) {
	    printf(rfmt, AuxVec(bp)[0]);
	    printf(rfmt, AuxVec(bp)[1]);
	    printf(rfmt, AuxVec(bp)[2]);
	}
	printf("\n");
    }
}
Ejemplo n.º 28
0
bool Line::ContainsPoint(const Point3D& point) const
{
	Float slope = CalculateSlope(p1, point);
	return (Smooth(slope) == Smooth(GetSlope()));
}
Ejemplo n.º 29
0
void ac::BlurHighToLow(cv::Mat &frame) {
    static MatrixCollection<16> collection;
    HighToLow(frame);
    Smooth(frame, &collection);
    AddInvert(frame);
}
Ejemplo n.º 30
0
bool MeshObject::LoadPLY(const char *filename, Material *mtl) {
	// Open file
	FILE *f = fopen(filename, "r");
	if (f == 0) {
		printf("ERROR: MeshObject::LoadPLY()- Can't open '%s'\n", filename);
		return false;
	}

	// Read header
	char tmp[256];
	int numverts = 0, numtris = 0;
	int posprop = -99, normprop = -99;
	int props = 0;
	while (1) {
		fgets(tmp, 256, f);
		if (strncmp(tmp, "element vertex", 14) == 0)
			numverts = atoi(&tmp[14]);
		if (strncmp(tmp, "element face", 12) == 0)
			numtris = atoi(&tmp[12]);
		if (strncmp(tmp, "property", 8) == 0) {
			int len = strlen(tmp);
			if (strncmp(&tmp[len - 3], " x", 2) == 0) posprop = props;
			if (strncmp(&tmp[len - 3], "nx", 2) == 0) normprop = props;
			props++;
		}
		if (strcmp(tmp, "end_header\n") == 0) break;
	}
	if (posprop == -1) {
		printf("ERROR: MeshObject::LoadPLY()- No vertex positions found\n");
		fclose(f);
		return false;
	}

	// Read verts
	int i = 0;
	if (numverts>0) {
		NumVertexes = numverts;
		Vertexes = new Vertex[NumVertexes];

		for (i = 0; i<NumVertexes; i++) {
			fgets(tmp, 256, f);
			char *pch = strtok(tmp, " ");
			int prop = 0;
			while (pch) {
				if (prop == posprop) Vertexes[i].Position.x = float(atof(pch));
				if (prop == posprop + 1) Vertexes[i].Position.y = float(atof(pch));
				if (prop == posprop + 2) Vertexes[i].Position.z = float(atof(pch));
				if (prop == normprop) Vertexes[i].Normal.x = float(atof(pch));
				if (prop == normprop + 1) Vertexes[i].Normal.y = float(atof(pch));
				if (prop == normprop + 2) Vertexes[i].Normal.z = float(atof(pch));
				pch = strtok(0, " ");
				prop++;
			}
		}
	}

	// Read tris
	if (numtris>0) {
		if (mtl == 0) mtl = new LambertMaterial;
		NumTriangles = numtris;
		Triangles = new Triangle[numtris];
		for (i = 0; i<numtris; i++) {
			int count, i0, i1, i2;
			fscanf(f, "%d %d %d %d\n", &count, &i0, &i1, &i2);
			if (count != 3) {
				printf("ERROR: MeshObject::LoadPLY()- Only triangles are supported\n");
				fclose(f);
				return false;
			}
			Triangles[i].Init(&Vertexes[i0], &Vertexes[i1], &Vertexes[i2], mtl);
		}
	}

	// Smooth
	if (normprop<0) Smooth();

	// Close file
	fclose(f);
	printf("Loaded %d triangles from file '%s'\n", numtris, filename);
	return true;
}