Example #1
0
void test_access (charT, Traits*, Allocator*, 
                  const StringFunc     &func,
                  const StringTestCase &tcase)
{
    typedef std::basic_string <charT, Traits, Allocator> String;
    typedef typename String::size_type                   SizeT;

    static const std::size_t BUFSIZE = 256;

    static charT wstr_buf [BUFSIZE];
    std::size_t str_len = sizeof wstr_buf / sizeof *wstr_buf;
    charT* wstr = rw_expand (wstr_buf, tcase.str, tcase.str_len, &str_len);

    // construct the string object 
    /* const */ String str (wstr, str_len);
    const       String const_str = str;

    if (wstr != wstr_buf)
        delete[] wstr;

    wstr = 0;

    // save the state of the string object before the call
    // to detect wxception safety violations (changes to
    // the state of the object after an exception)
    const StringState str_state (rw_get_string_state (str));

#ifndef _RWSTD_NO_EXCEPTIONS

    // is some exception expected ?
    const char* expected = 1 == tcase.bthrow ? exceptions[1] : 0;
    const char* caught = 0;

#endif   // _RWSTD_NO_EXCEPTIONS

    try {

        const charT *pres = 0;

        switch (func.which_) {

        case OpIndex (size):
            pres = &str [SizeT (tcase.off)];
            break;

        case OpIndex (const_size):
            pres = &const_str [SizeT (tcase.off)];
            break;

        case At (size):
            pres = &str.at (SizeT (tcase.off));
            break;

        case At (const_size):
            pres = &const_str.at (SizeT (tcase.off));
            break;

        default:
            RW_ASSERT (!"test logic error: unknown access overload");
            return;
        }

        const char exp_res [2] = {
            NPOS != tcase.nres ? char (tcase.nres) : char (),
            char ()
        };

        const bool success = 1 == rw_match (exp_res, pres, 1);
        rw_assert (success, 0, tcase.line,
                   "line %d. %{$FUNCALL} == %{#c}, got %{#c}",
                   __LINE__, tcase.nres, *pres);
    }

#ifndef _RWSTD_NO_EXCEPTIONS

    catch (const std::out_of_range &ex) {
        caught = exceptions [1];
        rw_assert (caught == expected, 0, tcase.line,
                   "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
                   "unexpectedly%{;} caught std::%s(%#s)",
                   __LINE__, 0 != expected, expected, caught, ex.what ());
    }
    catch (const std::exception &ex) {
        caught = exceptions [4];
        rw_assert (0, 0, tcase.line,
                   "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
                   "unexpectedly%{;} caught std::%s(%#s)",
                   __LINE__, 0 != expected, expected, caught, ex.what ());
    }
    catch (...) {
        caught = exceptions [0];
        rw_assert (0, 0, tcase.line,
                   "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
                   "unexpectedly%{;} caught %s",
                   __LINE__, 0 != expected, expected, caught);
    }

#endif   // _RWSTD_NO_EXCEPTIONS

    if (caught) {
        // verify that an exception thrown during allocation
        // didn't cause a change in the state of the object
        str_state.assert_equal (rw_get_string_state (str),
                                __LINE__, tcase.line, caught);
    }
}
Example #2
0
	T operator[](size_t nIndex) const
	{
		return At(nIndex);
	}
Example #3
0
  Plane::Plane(const std::vector<Point3d>& points)
    : m_a(0.0), m_b(0.0), m_c(0.0), m_d(0.0)
  {
    unsigned N = points.size();
    if (N < 3){
      LOG_AND_THROW("Cannot compute plane with fewer than three points");
    }else if (N == 3){

      // duplicates code in point and normal ctor, points[1] is the point and (a x b) is the normal
      Point3d point = points[1];
      Vector3d a = points[1]-points[0];
      Vector3d b = points[2]-points[1];
      Vector3d thisNormal = a.cross(b);

      if (!thisNormal.normalize()){
        LOG_AND_THROW("Cannot initialize plane because normal is undefined");
      }

      m_a = thisNormal.x();
      m_b = thisNormal.y();
      m_c = thisNormal.z();
      m_d = -thisNormal.x()*point.x() - thisNormal.y()*point.y() - thisNormal.z()*point.z();

    }else{

      bool foundSolution = false;
      double tol = 1e-8; // 0.0001 was too big for the determinant tolerance, 1e-12 was too small
      double maxDet = tol;

      // solve the equation ax+by+cz+d=0 in a few different ways, keep the best one

      {
        // Ax = b, x = [a/c; b/c; d/c]
        Matrix A(N,3);
        Matrix At(3,N);
        Vector b(N);
        for (unsigned i = 0; i < N; ++i){
          A(i,0) = points[i].x() - points[0].x(); 
          A(i,1) = points[i].y() - points[0].y();
          A(i,2) = 1.0;
          At(0,i) = A(i,0); 
          At(1,i) = A(i,1);
          At(2,i) = A(i,2);
          b[i] = -(points[i].z() - points[0].z());
        }
      
        Matrix AtA = prod(At, A);
        double det = det3x3(AtA); // always positive for A'*A
        if (det > maxDet){
          Matrix AtAInv(3,3);
          bool test = invert(AtA, AtAInv);
          if (test){
            maxDet = det;
            Vector x = prod(prod(AtAInv, At), b);
            double a_c = x[0];
            double b_c = x[1];
            double d_c = x[2];

            // a = a_c*c
            // b = b_c*c
            // d = d_c*c
            // a^2 + b^2 + c^2 = 1
            // c^2*(a_c^2 + b_c^2 + 1) = 1

            m_c = 1.0/sqrt(a_c*a_c + b_c*b_c + 1.0);
            m_a = a_c*m_c;
            m_b = b_c*m_c;
            m_d = d_c*m_c - m_a*points[0].x() - m_b*points[0].y() - m_c*points[0].z();
            foundSolution = true;
          }
        }
      }

      {
        // Ax = b, x = [a/b; c/b; d/b]
        Matrix A(N,3);
        Matrix At(3,N);
        Vector b(N);
        for (unsigned i = 0; i < N; ++i){
          A(i,0) = points[i].x() - points[0].x(); 
          A(i,1) = points[i].z() - points[0].z();
          A(i,2) = 1.0;
          At(0,i) = A(i,0); 
          At(1,i) = A(i,1);
          At(2,i) = A(i,2);
          b[i] = -(points[i].y() - points[0].y());
        }
      
        Matrix AtA = prod(At, A);
        double det = det3x3(AtA); // always positive for A'*A
        if (det > maxDet){
          Matrix AtAInv(3,3);
          bool test = invert(AtA, AtAInv);
          if (test){
            maxDet = det;
            Vector x = prod(prod(AtAInv, At), b);
            double a_b = x[0];
            double c_b = x[1];
            double d_b = x[2];

            // a = a_b*b
            // c = c_b*b
            // d = d_b*b
            // a^2 + b^2 + c^2 = 1
            // b^2*(a_b^2 + c_b^2 + 1) = 1

            m_b = 1.0/sqrt(a_b*a_b + c_b*c_b + 1.0);
            m_a = a_b*m_b;
            m_c = c_b*m_b;
            m_d = d_b*m_b - m_a*points[0].x() - m_b*points[0].y() - m_c*points[0].z();
            foundSolution = true;
          }
        }
      }

      {
        // Ax = b, x = [b/a; c/a; d/a]
        Matrix A(N,3);
        Matrix At(3,N);
        Vector b(N);
        for (unsigned i = 0; i < N; ++i){
          A(i,0) = points[i].y() - points[0].y(); 
          A(i,1) = points[i].z() - points[0].z();
          A(i,2) = 1.0;
          At(0,i) = A(i,0); 
          At(1,i) = A(i,1);
          At(2,i) = A(i,2);
          b[i] = -(points[i].x() - points[0].x());
        }
      
        Matrix AtA = prod(At, A);
        double det = det3x3(AtA); // always positive for A'*A
        if (det > maxDet){
          Matrix AtAInv(3,3);
          bool test = invert(AtA, AtAInv);
          if (test){
            maxDet = det;
            Vector x = prod(prod(AtAInv, At), b);
            double b_a = x[0];
            double c_a = x[1];
            double d_a = x[2];

            // b = b_a*a
            // c = c_a*a
            // d = d_a*a
            // a^2 + b^2 + c^2 = 1
            // a^2*(b_a^2 + c_a^2 + 1) = 1

            m_a = 1.0/sqrt(b_a*b_a + c_a*c_a + 1.0);
            m_b = b_a*m_a;
            m_c = c_a*m_a;
            m_d = d_a*m_a - m_a*points[0].x() - m_b*points[0].y() - m_c*points[0].z();
            foundSolution = true;
          }
        }
      }

      if (!foundSolution){
        //std::stringstream ss;
        //ss << std::fixed << std::setprecision(20) << points << std::endl;
        //std::string s = ss.str();
        LOG_AND_THROW("Cannot compute plane for points " << points);
      }

      // get outward normal from vertices, plane outward normal should match sense of vertices
      // this corresponds to the other solution to the sqrt
      boost::optional<Vector3d> outwardNormal = getOutwardNormal(points);
      if (outwardNormal){
        double dot = m_a*outwardNormal.get().x() + m_b*outwardNormal.get().y() + m_c*outwardNormal.get().z();
        if (dot < 0){
          m_a = -m_a;
          m_b = -m_b;
          m_c = -m_c;
          m_d = -m_d;
        }
      }

      // test that normal has length 1
      double length = m_a*m_a + m_b*m_b + m_c*m_c;
      tol = 0.0001;
      OS_ASSERT(fabs(1.0-length) <= tol);
    }
  }
Example #4
0
void Delaunay::Build(const Array<Pointf>& p, double e)
{
	epsilon = e;
	epsilon2 = e * e;
	points <<= p;
	order = GetSortOrder(points, &PointOrder);
	tihull = -1;
	int npoints = p.GetCount();

#ifdef DELDUMP
	RLOG("Delaunay(" << npoints << " points)");
	for(int dd = 0; dd < npoints; dd++)
		RLOG("[" << dd << "] = " << points[dd]);
#endif

	triangles.Clear();
	if(order.IsEmpty())
		return;
	const Pointf *p0 = &points[order[0]];
	int xi = 0;
	do
		if(++xi >= points.GetCount())
			return;
	while(IsNear(*p0, points[order[xi]]));

	// pass 1: create pair of improper triangles
	CreatePair(order[0], order[xi]);
	while(++xi < npoints)
		AddHull(order[xi]);

#ifdef DELDUMP
	RLOG("//Delaunay: " << triangles.GetCount() << " triangles");
	for(int td = 0; td < triangles.GetCount(); td++)
	{
		const Triangle& t = triangles[td];
		RLOG(NFormat("[%d] = [%d, %d, %d] (%4v)",
			td, t[0], t[1], t[2],
			t.IsProper() ? (At(t, 1) - At(t, 0)) % (At(t, 2) - At(t, 1)) : double(Null))
			<< NFormat(" -> [%d & %d, %d & %d, %d & %d]",
			t.Next(0), t.NextIndex(0),
			t.Next(1), t.NextIndex(1),
			t.Next(2), t.NextIndex(2)));
	}
	RLOG("");
#endif

	int clean = 0;
	do
	{
		int old_clean = clean;
		clean = triangles.GetCount();
		for(int i = clean; --i >= old_clean;)
			if(triangles[i].IsProper())
			{
				Triangle& t = triangles[i];
				for(int x = 0; x < 3; x++)
				{
					int j = t.Next(x);
					Triangle& u = triangles[j];
					if(u.IsProper())
					{
						int x1 = x + 1, x2 = x + 2;
						if(x1 >= 3) x1 -= 3;
						if(x2 >= 3) x2 -= 3;
						Pointf A = At(t, x);
						Pointf B = At(t, x1);
						Pointf C = At(t, x2);
						int y = t.NextIndex(x);
						Pointf D = At(u, y);
						double t1 = (A - C) ^ (B - A);
						double t2 = (B - C) % (B - A);
						double u1 = (D - C) ^ (B - D);
						double u2 = (B - C) % (B - D);
						if(t1 * u2 < t2 * u1)
						{ // not locally Delaunay, flip
							int y1 = y + 1, y2 = y + 2;
							if(y1 >= 3) y1 -= 3;
							if(y2 >= 3) y2 -= 3;
#ifdef DELDUMP
							RLOG("Delaunay flip (" << i << " / " << x << ", " << j << " / " << y << ")");
							RLOG(i << ": " << t[x] << " - " << A << ", " << t[x1] << " - " << B << ", " << t[x2] << " - " << C);
							RLOG(j << ": " << u[y] << " - " << D << ", " << u[y1] << " - " << At(u, y1) << ", " << u[y2] << " - " << At(u, y2));
							RLOG("t1 = " << t1 << ", t2 = " << t2 << ", t = " << t1 / t2);
							RLOG("u1 = " << u1 << ", u2 = " << u2 << ", u = " << u1 / u2);
#endif
							Triangle ot = t;
							Triangle ou = u;
							ASSERT(ot[x1] == ou[y2] && ot[x2] == ou[y1]);
							t.Set(ot[x1], ou[y], ot[x]);
							u.Set(ou[y1], ot[x], ou[y]);
							Link(i, 0, j, 0);
							Link(i, 1, ot.Next(x2), ot.NextIndex(x2));
							Link(i, 2, ou.Next(y1), ou.NextIndex(y1));
							Link(j, 1, ou.Next(y2), ou.NextIndex(y2));
							Link(j, 2, ot.Next(x1), ot.NextIndex(x1));
							clean = i;
#ifdef DELDUMP
							RLOG("After flip: [" << i << "] = " << t[x] << ", " << t[x1] << ", " << t[y2]
								<< "; [" << j << "] = " << u[y] << ", " << u[y1] << ", " << u[y2]);
#endif
						}
					}
				}
			}
	}
	while(clean < triangles.GetCount());
}
Example #5
0
 const byte& BidirBuffer::operator[]( int index ) const
 {
     return At(index);
 }
Example #6
0
void BaseArray::GaussianSmooth(double sigma){

  std::vector< std::vector<double> > tmp;

  // make array for gaussian values
  int size = ceil(6 * sigma);
  if (size % 2 == 0) {
    size += 1;
  }
  double gauss[size];
  double weight = 0;
  for (int i = 0; i < size; i++){
    gauss[i] = Gaussian(i - (size - 1)/2, sigma);
    weight += gauss[i];
  }
  // normalize
  for (auto &i: gauss){
    i = i/weight;
  }

  // make sure the gauss filter is not bigger the the image itself
  std::pair<int, int> s = Size();
  if (s.first < size){
    std::cout << "x-direction to low" << std::endl;
    std::exit(1);
  }
  if (s.second < size){
    std::cout << "y-direction to low" << std::endl;
    std::exit(1);
  }

  tmp.resize(s.first);
  for (auto &i: tmp){
    i.resize(s.second);
  }

  // smoothing in x-Direction
  for (int i=0; i<s.first; i++){
    for (int j=0; j<s.second; j++){
      double sum = 0;
      for (int k=0; k<size; k++){
        sum += gauss[k] * At(i+k-(size-1)/2, j, true);
      }
      tmp[i][j] = sum;
    }
  }
  data = tmp;

  // smoothing in y-direction
  for (int i=0; i<s.first; i++){
    for (int j=0; j<s.second; j++){
      double sum = 0;
      for (int k=0; k<size; k++){
        sum += gauss[k] * At(i, j+k-(size-1)/2, true);
      }
      tmp[i][j] = sum;
    }
  }

  data = tmp;
}
Example #7
0
File: Parse.cpp Project: juherr/fit
  VALUE<PARSE> ceefit_call_spec PARSE::At(int i, int j, int k)
  {
    PTR<PARSE> parentParsePtr(At(i,j));

    return parentParsePtr->Parts->At(k);
  }
EXPORT_C TPacketLengths::TLength TPacketLengths::operator[](TInt aIndex)
	{
	return At(aIndex);
	}
EXPORT_C const TPacketLengths::TLength TPacketLengths::operator[](TInt aIndex) const
	{
	return At(aIndex);
	}
Example #10
0
   ml = cl->GetMenuList();
   
   ((TClassMenuItem*)ml->At(1))->SetTitle("Add histos...");
   ((TClassMenuItem*)ml->At(2))->SetTitle("Divide histos...");
   ((TClassMenuItem*)ml->At(3))->SetTitle("Draw panel...");
   ((TClassMenuItem*)ml->At(4))->SetTitle("Fit one function...");
   ((TClassMenuItem*)ml->At(5))->SetTitle("Fit panel...");
   ((TClassMenuItem*)ml->At(6))->SetTitle("Multiply histos...");
   ((TClassMenuItem*)ml->At(7))->SetTitle("Rebin...");
   ((TClassMenuItem*)ml->At(8))->SetTitle("Set maximum scale...");
   ((TClassMenuItem*)ml->At(9))->SetTitle("Set minimum scale...");
   ((TClassMenuItem*)ml->At(10))->SetTitle("Smooth histogram");
   ((TClassMenuItem*)ml->At(12))->SetTitle("Set name...");
   ((TClassMenuItem*)ml->At(13))->SetTitle("Set title...");
   ((TClassMenuItem*)ml->At(15))->SetTitle("Delete histogram");
   ((TClassMenuItem*)ml->At(16))->SetTitle("Draw class info");
   ((TClassMenuItem*)ml->At(17))->SetTitle("Draw clone");
   ((TClassMenuItem*)ml->At(18))->SetTitle("Dump information");
   ((TClassMenuItem*)ml->At(19))->SetTitle("Inspect");
   ((TClassMenuItem*)ml->At(20))->SetTitle("Set drawing option...");
   ((TClassMenuItem*)ml->At(22))->SetTitle("Set line attributes...");
   ((TClassMenuItem*)ml->At(24))->SetTitle("Set fill attributes...");
   ((TClassMenuItem*)ml->At(26))->SetTitle("Set marker attributes...");
   
// Remove separators at the end, between attributes
   mi = (TClassMenuItem*)ml->At(23);
   delete mi;
   mi = (TClassMenuItem*)ml->At(24);
   delete mi;
}
Example #11
0
 explicit VectorBase(const Matrix<T, 1, N>& matrix)
 {
     for(std::size_t i=0; i!=N; ++i)
         _elem[i] = At(matrix, 0, i);
 }
Example #12
0
//============================================================
// <T>根据列名获取某列上的数据。</T>
//
// @param pName 列的名字。
// @param default 没有指定名称列时返回的值。
// @return 该列上的数据。
//============================================================
TCharC* FCsvLine::Get(TCharC* pName, TCharC* pValue){
   TInt index = _pHeads->IndexOf(pName);
   return At(index, pValue);
}
Example #13
0
	inline const TData& operator[](const TKey& oKey) const
	{
		CHashIterator oIt = Find(oKey);
		return *At(oIt);
	}
Example #14
0
	inline const TData& GetItem(const CHashIterator& oIt) const
	{
		return *At(oIt);
	}
Example #15
0
void ThreadIABoardQueue<size>::GetBestResultMultiThread(bool make, const unsigned long long start, const unsigned long long stop, bool make2, const unsigned long long start2, const unsigned long long stop2, Board *best) const
{
    TRACE01 Traces() << "\n" << "LOG: void ThreadIABoardQueue<size>::GetBestResult2";
    double result = 0;
    Board temp;

    TRACE01 Traces() << "\n" << "LOG: Number of eleents =" << numberOfElements;
    TRACE01 Traces() << "\n" << "LOG: Number of do not forget eleents =" << doNotForgetnumberOfElements;


    if (make)
    {
        TRACE01 Traces() << "\n" << "LOG: make = true";
        TRACE01 Traces() << "\n" << "LOG: start =" << start;
        TRACE01 Traces() << "\n" << "LOG: stop =" << stop;

        result = At(0).GetPercentageResult();
        temp = At(0);

        TRACE01 Traces() << "\n" << "LOG: Current best result";
        TRACE01 temp.PrintDebug();

        for (unsigned long long i = 0; i<numberOfElements; i++)
        {
            if (result>At(i).GetPercentageResult())
            {
                result =  At(i).GetPercentageResult();
                temp = At(i);
            };
        };
    };

    if (make2)
    {
        TRACE01 Traces() << "\n" << "LOG: make2 == true";
        TRACE01 Traces() << "\n" << "LOG: start2 =" << start2;
        TRACE01 Traces() << "\n" << "LOG: stop2 =" << stop2;

        if (!make)
        {
            TRACE01 Traces() << "\n" << "LOG: !make = false";
            result = doNotForgetqueue[start2].GetPercentageResult();
            temp = doNotForgetqueue[start2];            
            TRACE01 temp.PrintDebug();
        };

        TRACE01 Traces() << "\n" << "LOG: Searching best";

        for (unsigned long long i = start2; i<stop2; i++)
        {
            if (result>doNotForgetqueue[i].GetPercentageResult())
            {
                result =  doNotForgetqueue[i].GetPercentageResult();
                temp = doNotForgetqueue[i];
                TRACE01 temp.PrintDebug();
            };
        };
    };

    TRACE01 Traces() << "\n" << "LOG: End of searching";
    *best = temp;
}
EXPORT_C TInt TPacketResults::operator[](TInt aIndex) const
	{
	return At(aIndex);
	}
Example #17
0
double BaseArray::operator() (int x, int y, bool mirror){
  return At(x, y, mirror);
}
Example #18
0
var StrassenDMM(Var A,Var B,size_t m,size_t p,size_t n,size_t bound)//m为M行数,n为N列数,p为n行数,bound为递归下界
{		
	if(m<=bound||n<=bound||p<=bound)
		return Matrix::Dot(A,B);
	else
	{
		var A11=Take(A,1,m/2,1,p/2);
		var A12=Take(A,1,m/2,p/2+1,p);
		var A21=Take(A,m/2+1,m,1,p/2);
		var A22=Take(A,m/2+1,m,p/2+1,p);
		var B11=Take(B,1,p/2,1,n/2);
		var B12=Take(B,1,p/2,n/2+1,n);
		var B21=Take(B,p/2+1,p,1,n/2);
		var B22=Take(B,p/2+1,p,n/2+1,n);

		var S1=Matrix::Add(A21,A22);
		var S2=Matrix::Sub(S1,A11);
		var S3=Matrix::Sub(A11,A21);
		var S4=Matrix::Sub(A12,S2);
		var T1=Matrix::Sub(B12,B11);
		var T2=Matrix::Sub(B22,T1);
		var T3=Matrix::Sub(B22,B12);
		var T4=Matrix::Sub(T2,B21);

		var P1=Matrix::StrassenDMM(A11,B11,m/2,p/2,n/2,bound);
		var P2=Matrix::StrassenDMM(A12,B21,m/2,p/2,n/2,bound);
		var P3=Matrix::StrassenDMM(S4,B22,m/2,p/2,n/2,bound);
		var P4=Matrix::StrassenDMM(A22,T4,m/2,p/2,n/2,bound);
		var P5=Matrix::StrassenDMM(S1,T1,m/2,p/2,n/2,bound);
		var P6=Matrix::StrassenDMM(S2,T2,m/2,p/2,n/2,bound);
		var P7=Matrix::StrassenDMM(S3,T3,m/2,p/2,n/2,bound);

		var U1=Matrix::Add(P1,P2);
		var U2=Matrix::Add(P1,P6);
		var U3=Matrix::Add(U2,P7);
		var U4=Matrix::Add(U2,P5);
		var U5=Matrix::Add(U4,P3);
		var U6=Matrix::Sub(U3,P4);
		var U7=Matrix::Add(U3,P5);

		var r=Vec(m);
		for (size_t i=0;i<m;++i)
		{
			var &c=At(r,i);
			c=Vec(n);
		}
		for (size_t i=0;i<m/2;++i)
		{
			for (size_t j=0;j<n/2;++j)
			{
				Entry(r,i,j)=Entry(U1,i,j);
			}
		}
		for (size_t i=0;i<m/2;++i)
		{
			for (size_t j=n/2;j<n;++j)
			{
				Entry(r,i,j)=Entry(U5,i,j-n/2);
			}
		}
		for (size_t i=m/2;i<m;++i)
		{
			for (size_t j=0;j<n/2;++j)
			{
				Entry(r,i,j)=Entry(U6,i-m/2,j);
			}
		}
		for (size_t i=m/2;i<m;++i)
		{
			for (size_t j=n/2;j<n;++j)
			{
				Entry(r,i,j)=Entry(U7,i-m/2,j-n/2);
			}
		}
		return r;
	}
}
	/*
	[] operator overload.  Allows indexing into the characters of this string.
	Equivalent to a call to At.

	@param _index - integer index into the string
	@return (char&) - character at the given index
	@assert - if the index is out of bounds
	*/
	char& operator [] (const size_t _index) const
		{ return At(_index); }
Example #20
0
BOOL gldInitialiseMesa_DX(
	DGL_ctx *lpCtx)
{
	GLD_driver_dx7	*gld = NULL;
	int				MaxTextureSize, TextureLevels;
	BOOL			bSoftwareTnL;

	if (lpCtx == NULL)
		return FALSE;

	gld = lpCtx->glPriv;
	if (gld == NULL)
		return FALSE;

	if (glb.bMultitexture) {
		lpCtx->glCtx->Const.MaxTextureUnits = gld->d3dCaps.wMaxSimultaneousTextures;
		// Only support MAX_TEXTURE_UNITS texture units.
		// ** If this is altered then the FVF formats must be reviewed **.
		if (lpCtx->glCtx->Const.MaxTextureUnits > GLD_MAX_TEXTURE_UNITS_DX7)
			lpCtx->glCtx->Const.MaxTextureUnits = GLD_MAX_TEXTURE_UNITS_DX7;
	} else {
		// Multitexture override
		lpCtx->glCtx->Const.MaxTextureUnits = 1;
	}

	lpCtx->glCtx->Const.MaxDrawBuffers = 1;

	// max texture size
//	MaxTextureSize = min(gld->d3dCaps8.MaxTextureHeight, gld->d3dCaps8.MaxTextureWidth);
	MaxTextureSize = min(gld->d3dCaps.dwMaxTextureHeight, gld->d3dCaps.dwMaxTextureWidth);
	if (MaxTextureSize == 0)
		MaxTextureSize = 256; // Sanity check

	//
	// HACK!!
	if (MaxTextureSize > 1024)
		MaxTextureSize = 1024; // HACK - CLAMP TO 1024
	// HACK!!
	//

	// TODO: Check this again for Mesa 5
	// Got to set MAX_TEXTURE_SIZE as max levels.
	// Who thought this stupid idea up? ;)
	TextureLevels = 0;
	// Calculate power-of-two.
	while (MaxTextureSize) {
		TextureLevels++;
		MaxTextureSize >>= 1;
	}
	lpCtx->glCtx->Const.MaxTextureLevels = (TextureLevels) ? TextureLevels : 8;

	// Defaults
	IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_LIGHTING, FALSE);
	IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
	IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_DITHERENABLE, TRUE);
	IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_SHADEMODE, D3DSHADE_GOURAUD);

	// Set texture coord set to be used with each stage
	IDirect3DDevice7_SetTextureStageState(gld->pDev, 0, D3DTSS_TEXCOORDINDEX, 0);
	IDirect3DDevice7_SetTextureStageState(gld->pDev, 1, D3DTSS_TEXCOORDINDEX, 1);

	// Set up Depth buffer
	IDirect3DDevice7_SetRenderState(gld->pDev, D3DRENDERSTATE_ZENABLE,
		(lpCtx->lpPF->dwDriverData!=D3DX_SF_UNKNOWN) ? D3DZB_TRUE : D3DZB_FALSE);

	// Set the view matrix
	{
		D3DXMATRIX	vm;
#if 1
		D3DXMatrixIdentity(&vm);
#else
		D3DXVECTOR3 Eye(0.0f, 0.0f, 0.0f);
		D3DXVECTOR3 At(0.0f, 0.0f, -1.0f);
		D3DXVECTOR3 Up(0.0f, 1.0f, 0.0f);
		D3DXMatrixLookAtRH(&vm, &Eye, &At, &Up);
		vm._31 = -vm._31;
		vm._32 = -vm._32;
		vm._33 = -vm._33;
		vm._34 = -vm._34;
#endif
		IDirect3DDevice7_SetTransform(gld->pDev, D3DTRANSFORMSTATE_VIEW, &vm);
	}

// DX7 does not support D3DRS_SOFTWAREVERTEXPROCESSING
/*
	if (gld->bHasHWTnL) {
		if (glb.dwTnL == GLDS_TNL_DEFAULT)
			bSoftwareTnL = FALSE; // HW TnL
		else {
			bSoftwareTnL = ((glb.dwTnL == GLDS_TNL_MESA) || (glb.dwTnL == GLDS_TNL_D3DSW)) ? TRUE : FALSE;
		}
	} else {
		// No HW TnL, so no choice possible
		bSoftwareTnL = TRUE;
	}
	IDirect3DDevice8_SetRenderState(gld->pDev, D3DRS_SOFTWAREVERTEXPROCESSING, bSoftwareTnL);
*/

// Dump this in a Release build as well, now.
//#ifdef _DEBUG
	ddlogPrintf(DDLOG_INFO, "HW TnL: %s",
//		gld->bHasHWTnL ? (bSoftwareTnL ? "Disabled" : "Enabled") : "Unavailable");
		gld->bHasHWTnL ? "Enabled" : "Unavailable");
//#endif

	// Set up interfaces to Mesa
	gldEnableExtensions_DX7(lpCtx->glCtx);
	gldInstallPipeline_DX7(lpCtx->glCtx);
	gldSetupDriverPointers_DX7(lpCtx->glCtx);

	// Signal a complete state update
	lpCtx->glCtx->Driver.UpdateState(lpCtx->glCtx, _NEW_ALL);

	// Start a scene
	IDirect3DDevice7_BeginScene(gld->pDev);
	lpCtx->bSceneStarted = TRUE;

	return TRUE;
}
Example #21
0
void Delaunay::AddHull(int i)
{
#ifdef DELDUMP
	RLOG("AddHull(" << i << ": " << points[i] << ")");
#endif
	ASSERT(tihull >= 0);
	Pointf newpt = points[i];
	int hi = tihull;
	int vf = -1, vl = -1;
	bool was_out = true, fix_out = false;
	int im = -1;
	double nd2 = 1e300;
	do
	{
		const Triangle& t = triangles[hi];
		Pointf t1 = At(t, 1), t2 = At(t, 2), tm = (t1 + t2) * 0.5;
		double d2 = Squared(t1 - newpt);
		if(d2 <= epsilon2)
		{
#ifdef DELDUMP
			RLOG("-> too close to " << t[1] << ": " << t1);
#endif
			return; // too close
		}
		if(d2 < nd2)
		{
			im = hi;
			nd2 = d2;
		}
		if((t2 - t1) % (newpt - tm) > epsilon2)
		{
#ifdef DELDUMP
			RLOG("IN[" << hi << "], was_out = " << was_out);
#endif
			if(was_out)
				vf = hi;
			if(!fix_out)
				vl = hi;
			was_out = false;
		}
		else
		{
#ifdef DELDUMP
			RLOG("OUT[" << hi << "], was_out = " << was_out);
#endif
			was_out = true;
			if(vl >= 0)
				fix_out = true;
		}
		hi = t.Next(1);
	}
	while(hi != tihull);
	if(vf < 0)
	{ // collinear, extend fan
		Triangle& tm = triangles[im];
		int in = tm.Next(2);
		Triangle& tn = triangles[in];

		int j = tm[1];

		int ia = triangles.GetCount(), ib = ia + 1;
#ifdef DELDUMP
		RLOG("collinear -> connect " << im << " -> " << ia << " -> " << ib << " -> " << in);
#endif
		triangles.Add().Set(-1, i, j);
		triangles.Add().Set(-1, j, i);
		LINK(ia, 0, ib, 0);
		LINK(ia, 2, ib, 1);
		LINK(ia, 1, im, 2);
		LINK(ib, 2, in, 1);
	}
	else
	{
		Triangle& tf = triangles[vf];
		Triangle& tl = triangles[vl];
		int xfn = tf.Next(2), xln = tl.Next(1);

		int xf = triangles.GetCount(), xl = xf + 1;
#ifdef DELDUMP
		RLOG("adding vertex " << i << ": " << points[i] << " to hull between " << vf << " and " << vl);
#endif
		triangles.Add().Set(-1, tf[1], i);
		triangles.Add().Set(-1, i, tl[2]);

		tihull = xf;
		tf[0] = i;
		for(int f = vf; f != vl; triangles[f = triangles[f].Next(1)][0] = i)
			;

		LINK(xf, 0, vf, 2);
		LINK(xl, 0, vl, 1);

		LINK(xf, 2, xfn, 1);
		LINK(xl, 1, xln, 2);

		LINK(xf, 1, xl, 2);
	}
}
Example #22
0
//--------------------------------------------------------------------------------------
// Create any D3D10 resources that aren't dependant on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D10CreateDevice( ID3D10Device* pd3dDevice, const DXGI_SURFACE_DESC* pBufferSurfaceDesc,
                                      void* pUserContext )
{
    HRESULT hr = S_OK;

    // Read the D3DX effect file
    DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
    // Set the D3D10_SHADER_DEBUG flag to embed debug information in the shaders.
    // Setting this flag improves the shader debugging experience, but still allows 
    // the shaders to be optimized and to run exactly the way they will run in 
    // the release configuration of this program.
    dwShaderFlags |= D3D10_SHADER_DEBUG;
    #endif
    hr = D3DX10CreateEffectFromFile( L"Tutorial08.fx", NULL, NULL, "fx_4_0", dwShaderFlags, 0, pd3dDevice, NULL,
                                         NULL, &g_pEffect, NULL, NULL );
    if( FAILED( hr ) )
    {
        MessageBox( NULL,
                    L"The FX file cannot be located.  Please run this executable from the directory that contains the FX file.", L"Error", MB_OK );
        V_RETURN( hr );
    }

    g_pTechnique = g_pEffect->GetTechniqueByName( "Render" );
    g_pWorldVariable = g_pEffect->GetVariableByName( "World" )->AsMatrix();
    g_pViewVariable = g_pEffect->GetVariableByName( "View" )->AsMatrix();
    g_pProjectionVariable = g_pEffect->GetVariableByName( "Projection" )->AsMatrix();
    g_pMeshColorVariable = g_pEffect->GetVariableByName( "vMeshColor" )->AsVector();
    g_pDiffuseVariable = g_pEffect->GetVariableByName( "txDiffuse" )->AsShaderResource();

    // Define the input layout
    D3D10_INPUT_ELEMENT_DESC layout[] =
    {
        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
    };
    UINT numElements = sizeof( layout ) / sizeof( layout[0] );

    // Create the input layout
    D3D10_PASS_DESC PassDesc;
    g_pTechnique->GetPassByIndex( 0 )->GetDesc( &PassDesc );
    V_RETURN( pd3dDevice->CreateInputLayout( layout, numElements, PassDesc.pIAInputSignature,
                                             PassDesc.IAInputSignatureSize, &g_pVertexLayout ) );

    // Set the input layout
    pd3dDevice->IASetInputLayout( g_pVertexLayout );

    // Create vertex buffer
    SimpleVertex vertices[] =
    {
        { D3DXVECTOR3( -1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 1.0f, 1.0f ) },
        { D3DXVECTOR3( -1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },

        { D3DXVECTOR3( -1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 1.0f, 1.0f ) },
        { D3DXVECTOR3( -1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },

        { D3DXVECTOR3( -1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },
        { D3DXVECTOR3( -1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },
        { D3DXVECTOR3( -1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 1.0f ) },
        { D3DXVECTOR3( -1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },

        { D3DXVECTOR3( 1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 1.0f ) },
        { D3DXVECTOR3( 1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },

        { D3DXVECTOR3( -1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 1.0f ) },
        { D3DXVECTOR3( -1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },

        { D3DXVECTOR3( -1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },
        { D3DXVECTOR3( 1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 1.0f, 1.0f ) },
        { D3DXVECTOR3( -1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },
    };

    D3D10_BUFFER_DESC bd;
    bd.Usage = D3D10_USAGE_DEFAULT;
    bd.ByteWidth = sizeof( SimpleVertex ) * 24;
    bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
    bd.CPUAccessFlags = 0;
    bd.MiscFlags = 0;
    D3D10_SUBRESOURCE_DATA InitData;
    InitData.pSysMem = vertices;
    V_RETURN( pd3dDevice->CreateBuffer( &bd, &InitData, &g_pVertexBuffer ) );

    // Set vertex buffer
    UINT stride = sizeof( SimpleVertex );
    UINT offset = 0;
    pd3dDevice->IASetVertexBuffers( 0, 1, &g_pVertexBuffer, &stride, &offset );

    // Create index buffer
    // Create vertex buffer
    DWORD indices[] =
    {
        3,1,0,
        2,1,3,

        6,4,5,
        7,4,6,

        11,9,8,
        10,9,11,

        14,12,13,
        15,12,14,

        19,17,16,
        18,17,19,

        22,20,21,
        23,20,22
    };

    bd.Usage = D3D10_USAGE_DEFAULT;
    bd.ByteWidth = sizeof( DWORD ) * 36;
    bd.BindFlags = D3D10_BIND_INDEX_BUFFER;
    bd.CPUAccessFlags = 0;
    bd.MiscFlags = 0;
    InitData.pSysMem = indices;
    V_RETURN( pd3dDevice->CreateBuffer( &bd, &InitData, &g_pIndexBuffer ) );

    // Set index buffer
    pd3dDevice->IASetIndexBuffer( g_pIndexBuffer, DXGI_FORMAT_R32_UINT, 0 );

    // Set primitive topology
    pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

    // Load the Texture
    hr = D3DX10CreateShaderResourceViewFromFile( pd3dDevice, L"seafloor.dds", NULL, NULL, &g_pTextureRV, NULL );

    // Initialize the world matrices
    D3DXMatrixIdentity( &g_World );

    // Initialize the view matrix
    D3DXVECTOR3 Eye( 0.0f, 3.0f, -6.0f );
    D3DXVECTOR3 At( 0.0f, 1.0f, 0.0f );
    D3DXVECTOR3 Up( 0.0f, 1.0f, 0.0f );
    D3DXMatrixLookAtLH( &g_View, &Eye, &At, &Up );

    // Update Variables that never change
    g_pViewVariable->SetMatrix( ( float* )&g_View );
    g_pDiffuseVariable->SetResource( g_pTextureRV );

    return S_OK;
}
Example #23
0
 const byte* BidirBuffer::Back( int offset /*= 0*/ ) const /* offset bytes from end of data */
 {
     ESS_ASSERT( Size() != 0 );
     return &At(Size() - offset - 1);
 }
Example #24
0
File: set.cpp Project: hyln9/nV
void Set(Var x, Var y)
{
	if(SymQ(x))
	{
		OwnValues[x] = y;
	}
	else if(VecQ(x) && VecQ(y))
	{
		size_t n = Size(x);
		size_t ny = Size(y);
		if (ny < n) {
			for (size_t i = 0; i < ny; ++i)
				Set(At(x,i),At(y,i));
			for (size_t i = ny; i < n; ++i)
				Set(At(x,i),At(y,ny - 1));
		}
		else {
			for (size_t i = 0; i < n; ++i)
				Set(At(x,i),At(y,i));
		}
	}
	else if(ExQ(x))
	{
		var head = Eval(Head(x));
		if(SymQ(head))
		{
			var body = Body(x);
			if(head == TAG(Part))
			{
				SetPart(body, y);
			}
			else if(head == TAG(Property))
			{
				if(SymQ(At(body,0)) && SymQ(At(body,1)))
					Properties[At(body,0)][At(body,1)] = y;
			} else if (head == TAG(Condition)) {
				SetConditionDownValue(body, y);
			} else if (head == TAG(DownValues)) {
				SetDownValues(At(body,0), y);
			}
			else
			{
				body = Eval(body);
				if(FixQ(body))
				{
					FactValues[head][body] = y;
				}
				else
				{
					SetDownValue(head, body, y);
				}
			}
		}
		else if(ExQ(head) && SymQ(Head(head)))
		{
			var body = Body(x);
			SetSubValue(head, body, y);
		}
		else
		{
			// TODO: more specific exception class
			throw LogicError(L"no assignment performed!");
		}
	}
	else
	{
		// TODO: more specific exception class
		throw LogicError(L"no assignment performed!");
	}
}
EXPORT_C TPtrC CMemSpyEngineChunkList::MdcaPoint( TInt aIndex ) const
    {
    const CMemSpyEngineChunkEntry& item = At( aIndex );
    return TPtrC( item.Caption() );
    }
Example #26
0
File: Frame.C Project: carlomt/cmos
SeedList Frame::FindSeeds(const double thres, const size_t fiducialSideDim,  const size_t seedSide, const size_t localMaximumCheckSide) const
{
#ifdef DEBUG
	std::cout<<" Frame::FindSeeds "<<std::endl;
	std::cout<<" Frame ID: "<<fId<<std::endl;
	std::cout.flush();
#endif
	//  SeedList *res=new SeedList(fId);
	SeedList res(fId);
#ifdef DEBUG
	std::cout<<" res malloc "<<std::endl;
	std::cout.flush();
#endif
	
	for(size_t j=fiducialSideDim; j<(fNRow-fiducialSideDim); j++)  //Ciclo su tutte le righe
	{
		for(size_t i=fiducialSideDim; i<(fNCol-fiducialSideDim); i++)   //Ciclo su tutte le colonne
		{
#ifdef DEBUG
			std::cout<<" Frame::FindSeeds i "<<i<<" j "<<j<<std::endl;
			std::cout<<" fNCol "<<fNCol<< " fNRow "<<fNRow<<std::endl;
			std::cout.flush();
#endif
			
			if( At(i,j) > thres )   //Se il pixel considerato è sopra soglia...
			{
				bool addThis=true;
				double thisCandidate = this->At(i,j);
#ifdef DEBUG
				std::cout<<" Frame::FindSeeds thisCandidate: "<<thisCandidate<<std::endl;
				std::cout.flush();
#endif
				//check neighbours
				const size_t lim=(localMaximumCheckSide-1)/2;
				for(size_t jj=(j-lim); jj<=(j+lim); jj++)
				{
					for(size_t ii=(i-lim); ii<=(i+lim); ii++)
					{
						if(thisCandidate < this->At(ii,jj))  //controllo se nei pixel vicini ce ne sono di piu intensi
						{
							addThis=false;
						}
					}
				}//end check neighbours
				if(addThis)                                                       //se era davvero il piu alto dei vicini...
				{
					Seed tmp(i,j,fId,seedSide);
					size_t step=(seedSide-1)/2;
#ifdef DEBUG
					std::cout<<std::endl<<"Adding a seed "<<thisCandidate <<std::endl;
					std::cout<<"step: "<<step<<std::endl;
					std::cout.flush();
#endif
					
					for(size_t jj=(j-step); jj<=(j+step); jj++)
					{
						for(size_t ii=(i-step); ii<=(i+step); ii++)
						{
							double ttt=At(ii,jj);
#ifdef DEBUG
							std::cout<<" adding the value "<<ttt<<std::endl;
							std::cout.flush();
#endif
							tmp.AddPixel(ttt);                                     //...lo salvo come seed (cioè salvo i 7x7=49 pixel attorno a lui
						}
					}
					res.Add(tmp);
				}
			}                                                                      //end if At(i,j) > thres
#ifdef DEBUG
			std::cout<<" Frame::FindSeeds this value: "<<this->At(i,j)<<std::endl;
			std::cout.flush();
#endif
		}                                                                          //end for i
	}                                                                              //end for j
#ifdef DEBUG
	//  std::cout<<" Frame::FindSeeds returning: "<<res->Size()<<std::endl;
	std::cout<<" Frame::FindSeeds returning: "<<res.Size()<<std::endl;
	std::cout.flush();
#endif
	return res;
}
RenderInstruction& RenderInstructionContainer::GetNextInstruction( BufferIndex bufferIndex )
{
  // At protects against running out of space
  return At( bufferIndex, mIndex[ bufferIndex ]++ );
}
Example #28
0
File: Frame.C Project: carlomt/cmos
int Frame::ReadFile(const std::string filename,  const bool isBinary)
{     
#ifdef DEBUG
  std::cout<<" Frame::ReadFile reading "<<filename<<std::endl;
#endif
  
  if(fNRow==0 || fNCol==0)
    {
      std::ostringstream msg;
      msg<<"Frame::ReadFile the number of row or col is 0, did you initialized them?";
      throwException(msg.str().c_str());
    }
  
  std::ifstream reader;
  
  int filelen;
  FILE * infile;
  //std::cout<<"Is file binary? "<< isBinary <<std::endl;
	
  if(isBinary)
    {
#ifdef DEBUG
		std::cout<<" Frame::ReadFile file is binary "<<std::endl;
		std::cout<<"File aperto correttamente? Pre "<<reader.is_open()<<std::endl;
#endif
		reader.open(filename.c_str(), std::ios::binary);
		
#ifdef DEBUG
		std::cout<<"File aperto correttamente? Post "<<reader.is_open()<<std::endl;
		//std::cout<<"Reading binary file"<<std::endl;
#endif
		const char *cstr = filename.c_str();
		infile = fopen(cstr,"rb");
		fseek(infile, 0, SEEK_END);
		filelen = ftell(infile);
		rewind(infile);
		//		std::cout << filelen << " read values (filelen)" <<std::endl;
    }
  else
	{
	  reader.open(filename.c_str(),std::ios_base::in);
		//std::cout <<"File is not binary" <<std::endl;
	}
  
  if(!reader.is_open())
    {
      std::ostringstream msg;
      msg<<"Frame::ReadFile input file: "<<filename;
      throwException(msg.str().c_str());
    }
  int counter=0;
  unsigned int tmp_ptr1;
  unsigned int tmp_ptr2;
  unsigned int tmp_value1, tmp_value2;
  //rewind(infile);
  int kk = 0;
  unsigned char *buffer = (unsigned char*)malloc(filelen);
  if(isBinary){
    int value = fread(buffer,filelen,sizeof(unsigned char),infile);   //***ATTENZIONE: qui leggo il file binario!***// anche se poi value è una variabile inutilizzata
    //std::cout <<"int value: "<< value <<std::endl;
  }
  
  for(size_t j=0; j<fNRow; j++)
    {
      for(size_t i=0; i<fNCol; i++)
	{
	  double tmp=-99;
	  if(isBinary){
	    tmp_ptr1 = (unsigned int)buffer[kk];
	    kk = kk+1;
	    tmp_ptr2 = (unsigned int)buffer[kk];
	    kk = kk+1;
	    tmp_value2 = tmp_ptr2;
	    tmp_value1 = tmp_ptr1;
	    tmp = tmp_value2*256 + tmp_value1;
#ifdef DEBUG
	    //				std::cout <<"tmp variable: "<< tmp <<std::endl;
	    //				std::cout <<"buffer: "<< buffer <<std::endl;
#endif
	    
	  }
	  /*if(reader.eof())
	    {
	    std::ostringstream msg1;
	    msg1<<"Frame::ReadFile input file  "<<filename;
	    msg1<<"shorter than expected ("<<fNRow*fNCol<<")";
	    msg1<<counter<<" values have been red";
	    throwException(msg1.str().c_str());
	    }*/
	  else{
	    //std::cout<<"File is not binary"<<std::endl;
	    reader.clear();                //added on 2018-01-23 by collamaf+amorusor for compatibility with Rosa's PC
	    reader >> tmp;
	  }
	  
	  Set(i,j,tmp);
	  if(tmp>=157)
	    {
	      std::ostringstream msg2;
	      msg2<<"Frame::ReadFile "<<i<<" "<<j<<"  in value: "<<tmp;
	      msg2<<"  out value: "<<At(i,j);
	      
#ifdef DEBUG
	      std::cout<<msg2.str()<<std::endl;
#endif
	      
	    }
	  counter++;
	}
    }
  reader.close();
  return counter;
}
Example #29
0
EXPORT_C TBool CAknAnimationData::DrawNextAnimationStep(CBitmapContext& aGc)
{
    if (Count() == 0)
    {
        // Call the user animation step
        TAnimStep step;
        TAnimMultiStep nullStep(step);
        nullStep.iDrawStep.SetType(EAnimNullStep);
        nullStep.iSubStep = (TUint16)iCurrentDrawStep;
        TBool done = DrawUserAnimationStep(aGc, nullStep);
        iCurrentDrawStep++;
        return done;
    }

    if (iCurrentDrawStep < Count())
    {
        TInt drawSteps = (*iDrawStepsPerAnimStep)[iCurrentAnimStep];
        TInt startingDrawStep = iCurrentDrawStep;
        TBool repeatAnimStep = EFalse;

        for (TInt ii=0; ii<drawSteps; ii++)
        {
            TAnimStep* drawStep = &(At(iCurrentDrawStep));

            switch (drawStep->Type())
            {
            case EAnimBlitPreviousView:
            {
                TAnimBlitStep* step = drawStep->BlitStep();
                aGc.BitBlt(TPoint(step->iDestX, step->iDestY), iOldBitmap);
            }
            break;
            case EAnimBlitNewView:
            {
                TAnimBlitStep* step = drawStep->BlitStep();
                aGc.BitBlt(TPoint(step->iDestX, step->iDestY), iViewBitmap);
            }
            break;
            case EAnimBlitPartPreviousView:
            {
                TAnimBlitStep* step = drawStep->BlitStep();
                aGc.BitBlt(TPoint(step->iDestX, step->iDestY), iOldBitmap,
                           TRect(TPoint(step->iSrcX, step->iSrcY), TSize(step->iWidth, step->iHeight)));
            }
            break;
            case EAnimBlitPartNewView:
            {
                TAnimBlitStep* step = drawStep->BlitStep();
                aGc.BitBlt(TPoint(step->iDestX, step->iDestY), iViewBitmap,
                           TRect(TPoint(step->iSrcX, step->iSrcY), TSize(step->iWidth, step->iHeight)));
            }
            break;
            case EAnimDrawLine:
            case EAnimRevealPartNewViewFromLeft:
            case EAnimRevealPartNewViewFromRight:
            case EAnimRevealPartNewViewFromTop:
            case EAnimRevealPartNewViewFromBottom:
            case EAnimBlitSlideNewView:
            case EAnimBlitSlideNewViewClearBehind:
            {
                // Make this a pending step. Cancel the animation if the append fails
                TRAPD(err, iPendingSteps->AppendL(TAnimMultiStep(*drawStep)));
                if (err != KErrNone)
                    return ETrue;
            }
            break;
            case EAnimSetColor:
            {
                TAnimSetColorStep* step = drawStep->SetColorStep();
                iDrawColor = TRgb(step->iRed, step->iGreen, step->iBlue);
            }
            break;
            case EAnimDrawRect:
            {
                TAnimLineDrawStep* step = drawStep->LineDrawStep();
                aGc.SetPenColor(iDrawColor);
                aGc.SetPenStyle(CGraphicsContext::ESolidPen);
                aGc.DrawRect(TRect(TPoint(step->iStartX, step->iStartY),TPoint(step->iEndX, step->iEndY)));
            }
            break;
            case EAnimDrawFilledRect:
            {
                TAnimLineDrawStep* step = drawStep->LineDrawStep();
                aGc.SetBrushColor(iDrawColor);
                aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
                aGc.SetPenStyle(CGraphicsContext::ENullPen);
                aGc.DrawRect(TRect(TPoint(step->iStartX, step->iStartY),TPoint(step->iEndX, step->iEndY)));
            }
            break;
            case EAnimWait:
            {
                TAnimWaitStep* step = drawStep->WaitStep();
                repeatAnimStep = ETrue;
                if (step->iSteps > 0)
                {
                    step->iSteps--;
                    if (step->iSteps == 0)
                        repeatAnimStep = EFalse;
                }
            }
            break;
            case EAnimWaitUntilComplete:
                if (iPendingSteps->Count())
                    repeatAnimStep = ETrue;
                break;
            default:
                // Type is user-defined, so add to the pending steps
                TRAPD(err, iPendingSteps->AppendL(TAnimMultiStep(*drawStep)));
                if (err != KErrNone)
                    return ETrue;
                break;
            }
            iCurrentDrawStep++;
        }

        // If this step needs to be repeated, reset the draw step counter
        // otherwise increment the current animation step
        if (repeatAnimStep)
        {
            iCurrentDrawStep = startingDrawStep;
        }
        else
        {
            iCurrentAnimStep++;
        }
    }


    TInt done = DrawPendingAnimationSteps(aGc);

    if (iCurrentDrawStep == Count() && done)
        return ETrue;

    return EFalse;
}
Example #30
0
T *CPile<T>::operator[](const TInt &aIndex) const
{
return At(aIndex);
}