Esempio n. 1
0
std::vector<double> libmaus2::math::Convolution::convolutionFFTW(
	std::vector<double> const &
		#if defined(LIBMAUS2_HAVE_FFTW)
		RA
		#endif
		,
	std::vector<double> const &
		#if defined(LIBMAUS2_HAVE_FFTW)
		RB
		#endif
)
{
	#if defined(LIBMAUS2_HAVE_FFTW)
	uint64_t const ra = RA.size();
	uint64_t const rb = RB.size();

	if ( ra*rb == 0 )
		return std::vector<double>(0);

	uint64_t const rfftn = (ra+rb-1);
	uint64_t const minsize = 4096;
	uint64_t const fftn = std::max(minsize,libmaus2::math::nextTwoPow(rfftn));

	Transform::shared_ptr_type planA = getPlan(fftn,true);
	Transform::shared_ptr_type planB = getPlan(fftn,true);
	Transform::shared_ptr_type planR = getPlan(fftn,false);

	FFTWConvMemBlock & CCin_A = planA->CCin;
	FFTWConvMemBlock & CCtmp_A = planA->CCout;

	FFTWConvMemBlock & CCin_B = planB->CCin;
	FFTWConvMemBlock & CCtmp_B = planB->CCout;

	FFTWConvMemBlock & CCtmp_C = planR->CCin;
	FFTWConvMemBlock & CCout = planR->CCout;

	for ( uint64_t i = 0; i < RA.size(); ++i )
		CCin_A.A[i][0] = RA[i];
	for ( uint64_t i = 0; i < RB.size(); ++i )
		CCin_B.A[i][0] = RB[i];

	planA->execute();
	planB->execute();

	for ( uint64_t i = 0; i < fftn; ++i )
	{
		std::complex<double> CA(CCtmp_A.A[i][0],CCtmp_A.A[i][1]);
		std::complex<double> CB(CCtmp_B.A[i][0],CCtmp_B.A[i][1]);
		std::complex<double> CC = CA * CB;
		CCtmp_C.A[i][0] = CC.real();
		CCtmp_C.A[i][1] = CC.imag();
	}

	planR->execute();

	std::vector<double> R(rfftn);
	for ( uint64_t i = 0; i < rfftn; ++i )
		R[i] = CCout.A[i][0] / fftn;

	returnPlan(planA);
	returnPlan(planB);
	returnPlan(planR);

	return R;
	#else
	libmaus2::exception::LibMausException lme;
	lme.getStream() << "[E] libmaus2::math::Convolution::convolutionFFTW: libmaus2 is built without fftw support" << std::endl;
	lme.finish();
	throw lme;
	#endif
}
Esempio n. 2
0
TCost CostArc(void* g, TIdNod s, TIdNod d)
{ if (s < 1 || s > N(g) || d < 1 || d > N(g)) return ArcInex;
  return CA(g, s, d);
}
Esempio n. 3
0
int ModifCost(void* g, TIdNod s, TIdNod d, TCost c)
{ if (s < 1 || s > N(g) || d < 1 || d > N(g)) return 0;
  CA(g, s, d) = c;
  return 1;
}
Esempio n. 4
0
void testcompact()
{
	std::string const fn("tmpfile");
	#if 0
	std::string const fn2("tmpfile2");
	std::string const fnm("tmpfile.merged");
	#endif

	::libmaus::util::TempFileRemovalContainer::setup();
	::libmaus::util::TempFileRemovalContainer::addTempFile(fn);
	
	uint64_t n = 1024*1024;
	unsigned int const b = 3;
	::libmaus::bitio::CompactArray CA(n,b);
	::libmaus::bitio::CompactArrayWriter CAW(fn,n,b);
	srand(time(0));
	for ( uint64_t i = 0; i < n; ++i )
	{
		CA.set(i,rand() & ((1ull<<b)-1));
		CAW.put(CA.get(i));
	}
	CAW.flush();
	#if 0
	::libmaus::aio::CheckedOutputStream COS(fn);
	CA.serialize(COS);
	COS.flush();
	COS.close();
	#endif
	
	::libmaus::aio::CheckedInputStream CIS(fn);
	std::cerr << "compact file size is " << ::libmaus::util::GetFileSize::getFileSize(CIS) << std::endl;
	assert ( static_cast< ::std::streampos > (CIS.tellg()) == static_cast< ::std::streampos >(0) );
	assert ( CIS.get() >= 0 );
	
	::libmaus::bitio::CompactDecoderWrapper W(fn,4096);
	
	W.seekg(0,std::ios::end);
	int64_t const fs = W.tellg();
	W.seekg(0,std::ios::beg);
	W.clear();
	
	assert ( fs == static_cast<int64_t>(n) );
	
	std::cerr << "n=" << n << " fs=" << fs << std::endl;
	
	for ( uint64_t i = 0; i < n; ++i )
	{
		assert ( W.tellg() == static_cast< ::std::streampos >(i) );
		int const v = W.get();
		assert ( v == static_cast<int>(CA[i]) );
		// std::cerr << static_cast<int>(W.get()) << " " << CA[i] << std::endl;
	}
	
	for ( uint64_t i = 0; i < n; i += (rand() % 256) )
	{
		W.clear();
		W.seekg(i);
		
		std::cerr << "seek to " << W.tellg() << std::endl;
		
		for ( uint64_t j = i; j < n; ++j )
		{
			assert ( W.tellg() == static_cast< ::std::streampos >(j) );
			int const v = W.get();
			assert ( v == static_cast<int>(CA[j]) );
		}
		
		uint64_t ii = n-i;
		W.clear();
		W.seekg(ii);

		for ( uint64_t j = ii; j < n; ++j )
		{
			assert ( W.tellg() == static_cast< ::std::streampos >(j) );
			int const v = W.get();
			assert ( v == static_cast<int>(CA[j]) );
		}
	}
}
Esempio n. 5
0
double Math::Triangle::distance(const Point2D& p, Point2D* closestPoint)
{
    //Source is: http://wonderfl.net/c/b27F

    Vector2D AB(_b.x - _a.x, _b.y - _a.y);
    Vector2D AP(p.x - _a.x, p.y - _a.y);
    double ABXAP = (AB.x * AP.y) - (AB.y * AP.x);

    Vector2D BC(_c.x - _b.x, _c.y - _b.y);
    Vector2D BP(p.x - _b.x, p.y - _b.y);
    double BCXBP = (BC.x * BP.y) - (BC.y * BP.x);

    Vector2D CA(_a.x - _c.x, _a.y - _c.y);
    Vector2D CP(p.x - _c.x, p.y - _c.y);
    double CAXCP = (CA.x * CP.y) - (CA.y * CP.x);

    double distance = 0;

    //+++ //inside
    if (ABXAP >= 0 && BCXBP >= 0 && CAXCP >=0)
    {
        if(closestPoint) {
            closestPoint->x = p.x;
            closestPoint->y = p.y;
        }
    }
    //-+- //vertex
    else if (ABXAP < 0 && BCXBP >= 0 && CAXCP < 0)
    {
        distance = AP.x * AP.x + AP.y * AP.y;
        if(closestPoint) {
            closestPoint->x = _a.x;
            closestPoint->y = _a.y;
        }
    }
    //--+ //vertex
    else if (ABXAP < 0 && BCXBP < 0 && CAXCP >= 0)
    {
        distance = BP.x * BP.x + BP.y * BP.y;
        if(closestPoint) {
            closestPoint->x = _b.x;
            closestPoint->y = _b.y;
        }
    }
    //+-- //vertex
    else if (ABXAP >= 0 && BCXBP < 0 && CAXCP < 0)
    {
        distance = CP.x * CP.x + CP.y * CP.y;
        if(closestPoint) {
            closestPoint->x = _c.x;
            closestPoint->y = _c.y;
        }
    }
    //-++ //edge
    else if (ABXAP < 0 && BCXBP >= 0 && CAXCP >= 0)
    {
        double wd = ((AB.x * AP.x) + (AB.y * AP.y) ) / ((AB.x * AB.x) + (AB.y * AB.y));
        if (wd < 0) {
            wd = 0;
        }
        if (wd > 1) {
            wd = 1;
        }
        Point2D r;
        r.x = _a.x + (_b.x - _a.x) * wd;
        r.y = _a.y + (_b.y - _a.y) * wd;

        if (closestPoint) {
            closestPoint->x = r.x;
            closestPoint->y = r.y;
        }
        r.x = p.x - r.x;
        r.y = p.y - r.y;
        distance = r.x * r.x + r.y * r.y;
    }
    //+-+ //edge
    else if (ABXAP >= 0 && BCXBP < 0 && CAXCP >= 0)
    {
        double wd = ((BC.x * BP.x) + (BC.y * BP.y) ) / ((BC.x * BC.x) + (BC.y * BC.y));
        if (wd < 0) {
            wd = 0;
        }
        if (wd > 1) {
            wd = 1;
        }
        Point2D r;
        r.x = _b.x + (_c.x - _b.x) * wd;
        r.y = _b.y + (_c.y - _b.y) * wd;

        if (closestPoint) {
            closestPoint->x = r.x;
            closestPoint->y = r.y;
        }
        r.x = p.x - r.x;
        r.y = p.y - r.y;
        distance = r.x * r.x + r.y * r.y;
    }
    //++- //edge
    else if (ABXAP >= 0 && BCXBP >= 0 && CAXCP < 0)
    {
        double wd = ((CA.x * CP.x) + (CA.y * CP.y) ) / ((CA.x * CA.x) + (CA.y * CA.y));
        if (wd < 0) {
            wd = 0;
        }
        if (wd > 1) {
            wd = 1;
        }
        Point2D r;
        r.x = _c.x + (_a.x - _c.x) * wd;
        r.y = _c.y + (_a.y - _c.y) * wd;

        if (closestPoint) {
            closestPoint->x = r.x;
            closestPoint->y = r.y;
        }
        r.x = p.x - r.x;
        r.y = p.y - r.y;
        distance = r.x * r.x + r.y * r.y;
    }

    return distance;
}
Esempio n. 6
0
int main(int argc, char** argv) {
    double res, resAtr, resFac;

    El::Initialize(argc, argv);

    bmpi::communicator world;
    int rank = world.rank();

    skybase::context_t context(23234);

    // Setup problem and righthand side
    // Using Skylark's uniform generator (as opposed to Elemental's)
    // will insure the same A and b are generated regardless of the number
    // of processors.
    matrix_type A =
        skyutil::uniform_matrix_t<matrix_type>::generate(m,
            n, El::DefaultGrid(), context);
    matrix_type b =
        skyutil::uniform_matrix_t<matrix_type>::generate(m,
            1, El::DefaultGrid(), context);

    regression_problem_type problem(m, n, A);

    boost::mpi::timer timer;
    double telp;

    sol_type x(n,1);

    rhs_type r(b);

    // Using QR
    timer.restart();
    exact_solver_type<skyalg::qr_l2_solver_tag> exact_solver(problem);
    exact_solver.solve(b, x);
    telp = timer.elapsed();
    check_solution(problem, b, x, r, res, resAtr, resFac);
    if (rank == 0)
        std::cout << "Exact (QR):\t\t\t||r||_2 =  "
                  << boost::format("%.2f") % res
                  << "\t\t\t\t\t\t\t||A' * r||_2 = " << boost::format("%.2e") % resAtr
                  << "\t\tTime: " << boost::format("%.2e") % telp << " sec"
                  << std::endl;
    double res_opt = res;

    skybase::Gemv(El::NORMAL, -1.0, problem.input_matrix, x, 1.0, r);

    // Using SNE (semi-normal equations)
    timer.restart();
    exact_solver_type<skyalg::sne_l2_solver_tag>(problem).solve(b, x);
    telp = timer.elapsed();
    check_solution(problem, b, x, r, res, resAtr, resFac);
    if (rank == 0)
        std::cout << "Exact (SNE):\t\t\t||r||_2 =  "
                  << boost::format("%.2f") % res
                  << "\t\t\t\t\t\t\t||A' * r||_2 = " << boost::format("%.2e") % resAtr
                  << "\t\tTime: " << boost::format("%.2e") % telp << " sec"
                  << std::endl;
    res_opt = res;

    // Again, using SNE, only with the computed interface (example; to be removed.)
    cmatrix CA(A);
    regression_problem_type1 problem1(m, n, CA);
    timer.restart();
    exact_solver_type1<skyalg::sne_l2_solver_tag>(problem1).solve(b, x);
    telp = timer.elapsed();
    check_solution(problem, b, x, r, res, resAtr, resFac);
    if (rank == 0)
        std::cout << "Exact (SNE) (COMPUTED):\t\t\t||r||_2 =  "
                  << boost::format("%.2f") % res
                  << "\t\t\t\t\t\t\t||A' * r||_2 = " << boost::format("%.2e") % resAtr
                  << "\t\tTime: " << boost::format("%.2e") % telp << " sec"
                  << std::endl;
    res_opt = res;

    // Using SVD
    timer.restart();
    exact_solver_type<skyalg::svd_l2_solver_tag>(problem).solve(b, x);
    telp = timer.elapsed();
    check_solution(problem, b, x, r, res, resAtr, resFac);
    if (rank == 0)
        std::cout << "Exact (SVD):\t\t\t||r||_2 =  "
                  << boost::format("%.2f") % res
                  << "\t\t\t\t\t\t\t||A' * r||_2 = " << boost::format("%.2e") % resAtr
                  << "\t\tTime: " << boost::format("%.2e") % telp << " sec"
                  << std::endl;
    res_opt = res;

    // Using LSQR
    skyalg::krylov_iter_params_t lsqrparams;
    lsqrparams.am_i_printing = rank == 0;
    lsqrparams.log_level = 0;
    timer.restart();
    exact_solver_type<
        skyalg::iterative_l2_solver_tag<
            skyalg::lsqr_tag > >(problem, lsqrparams)
        .solve(b, x);
    telp = timer.elapsed();
    check_solution(problem, b, x, r, res, resAtr, resFac);
    if (rank == 0)
        std::cout << "Exact (LSQR):\t\t\t||r||_2 =  "
                  << boost::format("%.2f") % res
                  << "\t\t||r - r*||_2 / ||b - r*||_2 = " << boost::format("%.2e") % resFac
                  << "\t||A' * r||_2 = " << boost::format("%.2e") % resAtr
                  << "\t\tTime: " << boost::format("%.2e") % telp << " sec"
                  << std::endl;

    // Using sketch-and-solve

#if 0 
    timer.restart();
    sketched_solver_type<skysk::JLT_t>(problem, t, context).solve(b, x);
    telp = timer.elapsed();
    check_solution(problem, b, x, r, res, resAtr, resFac);
    if (rank == 0)
        std::cout << "Sketch-and-Solve (JLT):\t\t||r||_2 =  "
                  << boost::format("%.2f") % res
                  << " (x " << boost::format("%.5f") % (res / res_opt) << ")"
                  << "\t||r - r*||_2 / ||b - r*||_2 = " << boost::format("%.2e") % resFac
                  << "\t||A' * r||_2 = " << boost::format("%.2e") % resAtr
                  << "\t\tTime: " << boost::format("%.2e") % telp << " sec"
                  << std::endl;
#endif

    timer.restart();
    sketched_solver_type<skysk::CWT_t>(problem, t, context).solve(b, x);
    telp = timer.elapsed();
    check_solution(problem, b, x, r, res, resAtr, resFac);
    if (rank == 0)
        std::cout << "Sketch-and-Solve (CWT):\t\t||r||_2 =  "
                  << boost::format("%.2f") % res
                  << " (x " << boost::format("%.5f") % (res / res_opt) << ")"
                  << "\t||r - r*||_2 / ||b - r*||_2 = " << boost::format("%.2e") % resFac
                  << "\t||A' * r||_2 = " << boost::format("%.2e") % resAtr
                  << "\t\tTime: " << boost::format("%.2e") % telp << " sec"
                  << std::endl;

    timer.restart();
    sketched_solver_type<skysk::FJLT_t>(problem, t, context).solve(b, x);
    telp = timer.elapsed();
    check_solution(problem, b, x, r, res, resAtr, resFac);
    if (rank == 0)
        std::cout << "Sketch-and-Solve (FJLT):\t||r||_2 =  "
                  << boost::format("%.2f") % res
                  << " (x " << boost::format("%.5f") % (res / res_opt) << ")"
                  << "\t||r - r*||_2 / ||b - r*||_2 = " << boost::format("%.2e") % resFac
                  << "\t||A' * r||_2 = " << boost::format("%.2e") % resAtr
                  << "\t\tTime: " << boost::format("%.2e") % telp << " sec"
                  << std::endl;

    // Accelerate-using-sketching
#if 0
    timer.restart();
    accelerated_exact_solver_type_sb<skysk::JLT_t>(problem, context).solve(b, x);
    telp = timer.elapsed();
    check_solution(problem, b, x, r, res, resAtr, resFac);
    if (rank == 0)
        std::cout << "Simplified Blendenpik (JLT):\t||r||_2 =  "
                  << boost::format("%.2f") % res
                  << " (x " << boost::format("%.5f") % (res / res_opt) << ")"
                  << "\t||r - r*||_2 / ||b - r*||_2 = " << boost::format("%.2e") % resFac
                  << "\t||A' * r||_2 = " << boost::format("%.2e") % resAtr
                  << "\t\tTime: " << boost::format("%.2e") % telp << " sec"
                  << std::endl;
#endif

    timer.restart();
    accelerated_exact_solver_type_sb<skysk::FJLT_t>(problem, context).solve(b, x);
    telp = timer.elapsed();
    check_solution(problem, b, x, r, res, resAtr, resFac);
    if (rank == 0)
        std::cout << "Simplified Blendenpik (FJLT):\t||r||_2 =  "
                  << boost::format("%.2f") % res
                  << " (x " << boost::format("%.5f") % (res / res_opt) << ")"
                  << "\t||r - r*||_2 / ||b - r*||_2 = " << boost::format("%.2e") % resFac
                  << "\t||A' * r||_2 = " << boost::format("%.2e") % resAtr
                  << "\t\tTime: " << boost::format("%.2e") % telp << " sec"
                  << std::endl;

    timer.restart();
    accelerated_exact_solver_type_sb<skysk::CWT_t>(problem, context).solve(b, x);
    telp = timer.elapsed();
    check_solution(problem, b, x, r, res, resAtr, resFac);
    if (rank == 0)
        std::cout << "Simplified Blendenpik (CWT):\t||r||_2 =  "
                  << boost::format("%.2f") % res
                  << " (x " << boost::format("%.5f") % (res / res_opt) << ")"
                  << "\t||r - r*||_2 / ||b - r*||_2 = " << boost::format("%.2e") % resFac
                  << "\t||A' * r||_2 = " << boost::format("%.2e") % resAtr
                  << "\t\tTime: " << boost::format("%.2e") % telp << " sec"
                  << std::endl;

    timer.restart();
    accelerated_exact_solver_type_blendenpik(problem, context).solve(b, x);
    telp = timer.elapsed();
    check_solution(problem, b, x, r, res, resAtr, resFac);
    if (rank == 0)
        std::cout << "Blendenpik:\t\t\t||r||_2 =  "
                  << boost::format("%.2f") % res
                  << " (x " << boost::format("%.5f") % (res / res_opt) << ")"
                  << "\t||r - r*||_2 / ||b - r*||_2 = " << boost::format("%.2e") % resFac
                  << "\t||A' * r||_2 = " << boost::format("%.2e") % resAtr
                  << "\t\tTime: " << boost::format("%.2e") % telp << " sec"
                  << std::endl;

    timer.restart();
    accelerated_exact_solver_type_lsrn(problem, context).solve(b, x);
    telp = timer.elapsed();
    check_solution(problem, b, x, r, res, resAtr, resFac);
    if (rank == 0)
        std::cout << "LSRN:\t\t\t\t||r||_2 =  "
                  << boost::format("%.2f") % res
                  << " (x " << boost::format("%.5f") % (res / res_opt) << ")"
                  << "\t||r - r*||_2 / ||b - r*||_2 = " << boost::format("%.2e") % resFac
                  << "\t||A' * r||_2 = " << boost::format("%.2e") % resAtr
                  << "\t\tTime: " << boost::format("%.2e") % telp << " sec"
                  << std::endl;

    return 0;
}
Esempio n. 7
0
	BEGIN_ELSE
	DO_RETURN_Z;
	END_IF
}

unsigned char CCBuffer::readUChar()
{
	DO_RETURN_R((unsigned char)readChar());
}

short CCBuffer::readShort()
{
	BEGIN_IF(isReadable(sizeof(short)))
#if MEMORYTYPE_REVERSE
	DO_ASSIGN(char p_temp[sizeof(short)], {0});
	memcpy(p_temp, CA(_p_buffer, _u_read_pos), sizeof(short));
	std::reverse(QZ(p_temp[0]), QZ(p_temp[sizeof(short)]));
	DO_ASSIGN(short ret, QV((short*)p_temp));
#else
	DO_ASSIGN(short ret, QV((short*)(CA(_p_buffer, _u_read_pos))));
#endif
	AA(_u_read_pos, sizeof(short));
	DO_RETURN_R(ret);
	BEGIN_ELSE
	DO_RETURN_Z;
	END_IF
}

unsigned short CCBuffer::readUShort()
{
	DO_RETURN_R(TO_USHORT(readShort()));
Esempio n. 8
0
static void connected_components() {
  int *color;
  int i;
  int clusters, singletons;

  CA(color, n_seq, sizeof(int));
  CA(back_edges, n_seq, sizeof(int *));
  CA(tree_edges, n_seq, sizeof(int *));
  CA(n_tedges, n_seq, sizeof(int));
  CA(n_bedges, n_seq, sizeof(int));


  n_components = 0;
  components = NULL;
  component_size = NULL;
  for(i=0;i<n_seq;i++) {
    if (color[i]) continue;
    if (chimeric[i]) continue;

    PUSH(components, n_components, sizeof(int *));
    PUSH(component_size, n_components, sizeof(int));
    components[n_components] = NULL;
    component_size[n_components] = 0;
    cc_dfs_visit(color, components + n_components, 
		 component_size + n_components, i);
    n_components++;
  }


  fprintf(stderr,"Found %d connected components\n", n_components);
  CA(arti_points, n_seq, sizeof(int));
  n_arti = 0;
  clusters = singletons = 0;

  for(i=0;i<n_components;i++) {
    int j;

    if (component_size[i] > 1) {

      fprintf(stdout,">Cluster %d (%d sequences)\n",clusters,
	      component_size[i]);

      scan_arti_points(i);
      if (database_name) {
	for(j=0;j<component_size[i];j++) {
	  fprintf(stdout,"%s ",seqname_data + 
		  seqmeta[components[i][j]].name_pos);
	}
      } else {
	for(j=0;j<component_size[i];j++) {
	  fprintf(stdout,"%d ",components[i][j]);
	}
      }
      fprintf(stdout,"\n");
      clusters++;
    } else {
      singletons++;
    }
  }

  fprintf(stdout,">Singletons (%d sequences)\n", singletons);
  if (database_name) {
    for(i=0;i<n_components;i++) {
      if (component_size[i] == 1) {
	fprintf(stdout,"%s ",seqname_data + 
		seqmeta[components[i][0]].name_pos);
      }
    }
  } else {
    for(i=0;i<n_components;i++) {
      if (component_size[i] == 1) {
	fprintf(stdout,"%d ",components[i][0]);
      }
    }
  }
  fprintf(stdout,"\n");

  free(color);
  free(back_edges);
  free(tree_edges);
  free(n_tedges);
  free(n_bedges);
  fprintf(stderr,"Clusters %d Singletons %d\n",clusters,singletons);
}
Esempio n. 9
0
static int		recv_flash	(CalcHandle* handle, FlashContent* content, VarRequest* vr)
{
	uint16_t aids[] = { AID_ARCHIVED, AID_VAR_VERSION };
	const int naids = sizeof(aids) / sizeof(uint16_t);
	CalcAttr **attrs;
	const int nattrs = 1;
	char fldname[40], varname[40];
	uint8_t *data;
	char *utf8;
	
	int page;
	uint16_t data_addr = 0x4000;
	uint16_t data_page = 0;
	int r, q;

	utf8 = ticonv_varname_to_utf8(handle->model, vr->name, vr->type);
	g_snprintf(update_->text, sizeof(update_->text), "%s", utf8);
	g_free(utf8);
	update_label();

	attrs = ca_new_array(nattrs);
	attrs[0] = ca_new(AID_VAR_TYPE2, 4);
	attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x07;
	attrs[0]->data[2] = 0x00; attrs[0]->data[3] = vr->type;

	TRYF(cmd_s_var_request(handle, "", vr->name, naids, aids, 
			       nattrs, CA(attrs)));
	ca_del_array(nattrs, attrs);
	attrs = ca_new_array(naids);
	TRYF(cmd_r_var_header(handle, fldname, varname, attrs));
	TRYF(cmd_r_var_content(handle, NULL, &data));

	content->model = handle->model;
	strcpy(content->name, vr->name);
	content->data_type = vr->type;
	content->device_type = DEVICE_TYPE_83P;
	content->num_pages = 2048;	// TI83+ has 512 KB of FLASH max
	content->pages = tifiles_fp_create_array(content->num_pages);

	q = vr->size / FLASH_PAGE_SIZE;
	r = vr->size % FLASH_PAGE_SIZE;

	update_->cnt2 = 0;
	update_->max2 = q;

	for(page = 0; page < q; page++)
	{
		FlashPage *fp = content->pages[page] = tifiles_fp_create();

		fp->addr = data_addr;
		fp->page = data_page++;
		fp->flag = 0x80;
		fp->size = FLASH_PAGE_SIZE;
		fp->data = tifiles_fp_alloc_data(FLASH_PAGE_SIZE);
		memcpy(fp->data, data + FLASH_PAGE_SIZE*page, FLASH_PAGE_SIZE);

		update_->cnt2 = page;
		update_->pbar();
	}
	{
		FlashPage *fp = content->pages[page] = tifiles_fp_create();

		fp->addr = data_addr;
		fp->page = data_page++;
		fp->flag = 0x80;
		fp->size = r;
		fp->data = tifiles_fp_alloc_data(FLASH_PAGE_SIZE);
		memcpy(fp->data, data + FLASH_PAGE_SIZE*page, r);

		update_->cnt2 = page;
		update_->pbar();
	}
	content->num_pages = page+1;

	g_free(data);	
	ca_del_array(naids, attrs);
	return 0;
}
Esempio n. 10
0
static int		send_flash	(CalcHandle* handle, FlashContent* content)
{
	FlashContent *ptr;
	int i;
	char *utf8;
	CalcAttr **attrs;
	const int nattrs = 2;

	uint8_t *data;
	uint32_t size;

	// search for data header
	for (ptr = content; ptr != NULL; ptr = ptr->next)
		if(ptr->data_type == TI83p_AMS || ptr->data_type == TI83p_APPL)
			break;
	if(ptr == NULL)
		return -1;
	if(ptr->data_type != TI83p_APPL)
		return -1;

#if 0
	printf("#pages: %i\n", ptr->num_pages);
	printf("type: %02x\n", ptr->data_type);
	for (i = 0; i < ptr->num_pages; i++) 
	{
		FlashPage *fp = ptr->pages[i];

		printf("page #%i: %04x %02x %02x %04x\n", i,
			fp->addr, fp->page, fp->flag, fp->size);
	}
	printf("data length: %08x\n", ptr->data_length);

	return 0;
#endif

	size = ptr->num_pages * FLASH_PAGE_SIZE;
	data = tifiles_fp_alloc_data(size);	// must be rounded-up

	update_->cnt2 = 0;
	update_->max2 = ptr->num_pages;

	for (i = 0; i < ptr->num_pages; i++) 
	{
		FlashPage *fp = ptr->pages[i];
		memcpy(data + i*FLASH_PAGE_SIZE, fp->data, FLASH_PAGE_SIZE);

		update_->cnt2 = i;
		update_->pbar();
	}
	{
		FlashPage *fp = ptr->pages[--i];
		memset(data + i*FLASH_PAGE_SIZE + fp->size, 0x00, FLASH_PAGE_SIZE - fp->size); 

		update_->cnt2 = i;
		update_->pbar();
	}

	// send
	utf8 = ticonv_varname_to_utf8(handle->model, ptr->name, ptr->data_type);
	g_snprintf(update_->text, sizeof(update_->text), "%s", utf8);
	g_free(utf8);
	update_label();

	attrs = ca_new_array(nattrs);
	attrs[0] = ca_new(AID_VAR_TYPE, 4);
	attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x07;
	attrs[0]->data[2] = 0x00; attrs[0]->data[3] = ptr->data_type;
	attrs[1] = ca_new(AID_ARCHIVED, 1);
	attrs[1]->data[0] = 0;
	
	TRYF(cmd_s_rts(handle, "", ptr->name, size, nattrs, CA(attrs)));
	TRYF(cmd_r_data_ack(handle));
	TRYF(cmd_s_var_content(handle, size, data));
	TRYF(cmd_r_data_ack(handle));
	TRYF(cmd_s_eot(handle));

	return 0;
}
Esempio n. 11
0
void ObjectAnimations::MoveToFrame(unsigned int frame)
{
	Variant sval;
	Variant eval;
	unsigned int sframe, eframe;

	for(map<int, set<AnimationKey> >::iterator i = animations.begin(); i!=animations.end(); i++)
	{
		if(i->second.size()==0) continue;
		set<AnimationKey>::iterator end, start;
		end = i->second.upper_bound(frame);
		start = end;
		--start;
		
		if(end==i->second.end())
		{
			sval = start->val;
			sframe = start->frame;
			eval = start->val;
			eframe = start->frame;
		}
		else
		{
			sval = start->val;
			sframe = start->frame;

			eval = end->val;
			eframe = end->frame;
		}

		unsigned int tframes = eframe - sframe;
		if(tframes==0) tframes = 1;
		float t = (frame - sframe) / (float)tframes;

		if(sval.GetType() == Variant::Int && eval.GetType() == Variant::Int)
		{
			int s = sval;
			int e = eval;
			int c = (int)(s + (e - s) * t);
		}
		else if(sval.GetType() == Variant::Float && eval.GetType() == Variant::Float)
		{
			float s = sval;
			float e = eval;
			float c = s + (e - s) * t;

			if(i->first == ANIM_TYPE_POSX)
			{
				if(!obj.IsValid()) return;
				RectangleF& pos = obj.GetObject()->GetObjectArea();
				float width = pos.right - pos.left;
				pos.left = c;
				pos.right = pos.left + width;
			}
			else if(i->first == ANIM_TYPE_POSY)
			{
				if(!obj.IsValid()) return;
				RectangleF& pos = obj.GetObject()->GetObjectArea();
				float height = pos.bottom - pos.top;
				pos.top = c;
				pos.bottom = pos.top + height;
			}
			else if(i->first == ANIM_TYPE_SCALEX)
			{
				if(!obj.IsValid()) return;
				RectangleF& pos = obj.GetObject()->GetObjectArea();
				pos.bottom = pos.top + c;
			}
			else if(i->first == ANIM_TYPE_SCALEY)
			{
				if(!obj.IsValid()) return;
				RectangleF& pos = obj.GetObject()->GetObjectArea();
				pos.bottom = pos.top + c;
			}
			else if(i->first == ANIM_TYPE_ROTATION)
			{
				if(!obj.IsValid()) return;
				obj.GetObject()->SetAngle(c);
			}
			else if(i->first == ANIM_TYPE_CPOSX)
			{
				Game->GetMainContainer()->GetCamera().m_pos.left = c;
				Game->GetMainContainer()->AdjustCamera();
			}
			else if(i->first == ANIM_TYPE_CPOSY)
			{
				Game->GetMainContainer()->GetCamera().m_pos.top = c;
				Game->GetMainContainer()->AdjustCamera();
			}
			else if(i->first == ANIM_TYPE_CZOOM)
			{
				Game->GetMainContainer()->GetCamera().m_zoom = c;
				Game->GetMainContainer()->AdjustCamera();
			}
		}
		else if(sval.GetType() == Variant::UInt && eval.GetType() == Variant::UInt)
		{
			unsigned int s = sval;
			unsigned int e = eval;
			int c = (unsigned int)(s + (e - s) * t);
			if(i->first == ANIM_TYPE_BCOLOR)
			{
				if(!obj.IsValid()) return;
				ColorARGB32 CA(s), CB(e);
				ColorARGB32 CE((unsigned char)(CA.GetA() + (CB.GetA() - CA.GetA()) * t), (unsigned char)(CA.GetR() + (CB.GetR() - CA.GetR()) * t), (unsigned char)(CA.GetG() + (CB.GetG() - CA.GetG()) * t), (unsigned char)(CA.GetB() + (CB.GetB() - CA.GetB()) * t));
				obj.GetObject()->m_backcolor = CE;
			}
		}
	}
}
Esempio n. 12
0
 void TypeOfFE_RTmodif::FB(const bool * whatd,const Mesh & Th,const Triangle & K,const R2 & PHat,RNMK_ & val) const
{ //  
//  const Triangle & K(FE.T);
  R2 P(K(PHat));
  R2 A(K[0]), B(K[1]),C(K[2]);
  R la=1-PHat.x-PHat.y,lb=PHat.x,lc=PHat.y; 
  R2 Dla(K.H(0)), Dlb(K.H(1)), Dlc(K.H(2));
  if (val.N() <3) 
   throwassert(val.N() >=3);
  throwassert(val.M()==2 );

  R2 AB(A,B),AC(A,C),BA(B,A),BC(B,C),CA(C,A),CB(C,B);

  R aa0= 1./(((AB,Dlb) + (AC,Dlc))*K.area);
  R aa1= 1./(((BA,Dla) + (BC,Dlc))*K.area);
  R aa2= 1./(((CA,Dla) + (CB,Dlb))*K.area);
  int i=0;
  R a0=   &K[ (i+1)%3] < &K[ (i+2)%3] ? aa0 : -aa0 ;
  i=1;
  R a1=   &K[ (i+1)%3] < &K[ (i+2)%3] ? aa1 : -aa1 ;
  i=2;
  R a2=   &K[ (i+1)%3] < &K[ (i+2)%3] ? aa2 : -aa2 ;
 // if (Th(K)< 2) cout << Th(K) << " " <<  A << " "  << B << " " << C << "; " <<  a0 << " " << a1 << " "<< a2 << endl;;
 
  R2 Va= AB*(lb*a0) + AC*(lc*a0);
  R2 Vb= BA*(la*a1) + BC*(lc*a1);
  R2 Vc= CA*(la*a2) + CB*(lb*a2);
  R2 Va_x= AB*(Dlb.x*a0) + AC*(Dlc.x*a0);
  R2 Vb_x= BA*(Dla.x*a1) + BC*(Dlc.x*a1);
  R2 Vc_x= CA*(Dla.x*a2) + CB*(Dlb.x*a2);
  R2 Va_y= AB*(Dlb.y*a0) + AC*(Dlc.y*a0);
  R2 Vb_y= BA*(Dla.y*a1) + BC*(Dlc.y*a1);
  R2 Vc_y= CA*(Dla.y*a2) + CB*(Dlb.y*a2);
 
 if( whatd[op_id])
  {
    RN_ f0(val('.',0,0)); 
    RN_ f1(val('.',1,0)); 
    
    f0[0] = Va.x;
    f1[0] = Va.y;
    
    f0[1] = Vb.x;
    f1[1] = Vb.y;
    
    f0[2] = Vc.x;
    f1[2] = Vc.y;
  }
 // ----------------
 if( whatd[op_dx])
   {
     val(0,0,1) =  Va_x.x;  
     val(0,1,1) =  Va_x.y;  
     
     val(1,0,1) =  Vb_x.x;  
     val(1,1,1) =  Vb_x.y;  
     
     val(2,0,1) =  Vc_x.x;  
     val(2,1,1) =  Vc_x.y;
   }
 
 if( whatd[op_dy])
   {
     val(0,0,2) =  Va_y.x;  
     val(0,1,2) =  Va_y.y;  

     val(1,0,2) =  Vb_y.x;  
     val(1,1,2) =  Vb_y.y;  
     
  val(2,0,2) =  Vc_y.x;  
  val(2,1,2) =  Vc_y.y;  
   }
 
}