Beispiel #1
0
Array3d  Analysis::getParticleFluxKy(int sp) 
{
    Array3d G(RFields, RkyLD, RsLD); G = 0.;
    
    Array3z V2(RxLD, RkyLD, RzLD); V2 = 0.;
    Array3z W2(RxLD, RkyLD, RzLD); W2 = 0.;
   
  for(int s = NsLlD; s <= NsLuD; s++) {
      
      const double d6Z = M_PI * plasma->species(s).n0 * plasma->species(s).T0 * plasma->B0 * dv * dm * scaleXYZ;

        for(int m=NmLlD; m<= NmLuD;m++ ) { for(int z=NzLlD; z<= NzLuD;z++){ 
      
        // multiply in real-space 
        for(int x=NxLlD; x  <= NxLuD ;  x++) { for(int y_k=NkyLlD; y_k<= NkyLuD;y_k++) { 

            const cmplxd ky=cmplxd(0.,-fft->ky(y_k));
              
            V2(x,y_k,z) = ky * fields->phi(x,y_k,z,m,s);
        
             // integrate over velocity space
             W2(x,y_k,z) = sum(vlasov->f(x, y_k, z, RvLD, m, s)) * d6Z;
         }} 

           // V2(RxLD, RkyLD, RzLD) = 
           fft->multiply(V2, W2, A_xyz);
      
            // sum over x and z
            for(int x=NxLlD; x  <= NxLuD ;  x++) { G(Field::phi, RkyLD, s) +=  abs(A_xyz(x, RkyLD,z)) ; }
                 
        } }
   }


    
   return parallel->collect(G);

};
Beispiel #2
0
static void
initialize_data(uint32_t memsize, 
        uint32_t num_particles_x, uint32_t num_particles_y, 
        uint32_t num_levels, uint32_t num_coeffs)
{
    uint32_t num_particles = num_particles_x * num_particles_y;
    memory.free_memory = (uint8_t*)calloc(memsize, 1);
    memory.free_memory_size = memsize;
    
    data.positions = push_array(v2, num_particles);
    data.velocities = push_array(v2, num_particles);
    data.forces = push_array(v2, num_particles);
    data.num_particles = num_particles;
    
    /* initialize equidistant grid */
    v2 min_corner = V2(0, 0);
    v2 max_corner = V2(1, 1);
    v2 dim = max_corner - min_corner;
    float dx = dim.x / num_particles_x;
    float dy = dim.y / num_particles_y;
    uint32_t idx = 0;
    for(uint32_t j = 0; j < num_particles_y; j++) {
        for(uint32_t i = 0; i < num_particles_x; i++) {
            data.positions[idx] =
                min_corner + V2(i * dx, j * dy);
            data.velocities[idx] = V2(0,0);
            idx++;
        }
    }

    data.dim = dim;
    data.num_levels = num_levels;
    data.num_coeffs = num_coeffs;

    v2 half_dim = 0.5f * data.dim;
    initialize_quad_tree(&data.root_cell, half_dim, half_dim, 
            num_levels, num_coeffs);
}
Beispiel #3
0
//**********************************************************************************
//	
//**********************************************************************************
void	CMessageBox::SetText( const CString & text )
{
	m_pText->SetText( text );

	V2	text_size( m_pText->GetSize() + ( 2.f * BOX_BORDER ) );

	if ( text_size.x < CFont::GetDefaultFont()->GetStringSize( m_szTitle ).x + ( 2.f * BOX_BORDER.x ) )
	{
		text_size.x = CFont::GetDefaultFont()->GetStringSize( m_szTitle ).x + ( 2.f * BOX_BORDER.x );
	}

	SetPos( V2( 0.5f * ( CGfx::s_ScreenWidth - text_size.x ), 0.5f * ( CGfx::s_ScreenHeight - text_size.y ) ) );
	SetSize( text_size );
}
/**
 * Display options menu.
 * Menu will be centred on screen.
 */
    void
MenuOptions::own_resumeState()
{
    int contentW = m_container->getW();
    int contentH = m_container->getH();
    OptionAgent *options = OptionAgent::agent();
    int screenW = options->getAsInt("screen_width");
    int screenH = options->getAsInt("screen_height");

    /*FFNG*///FFNGApp::setGameState(FFNGApp::GAMESTATE_OPTIONS);  until I figure out how to get it back to previous state

    m_container->setShift(
            V2((screenW - contentW) / 2, (screenH - contentH) / 2));
}
bool TestParserStmt::TestClassVariable() {
  V("<?php class Test { public $data;}",
    "class Test {\npublic $data;\n}\n");

  V("<?php class Test { protected $data;}",
    "class Test {\nprotected $data;\n}\n");

  V("<?php class Test { private $data;}",
    "class Test {\nprivate $data;\n}\n");

  V("<?php class Test { static $data;}",
    "class Test {\npublic static $data;\n}\n");

  V("<?php class Test { private static $data;}",
    "class Test {\nprivate static $data;\n}\n");

  V("<?php class Test { private static $data=2;}",
    "class Test {\nprivate static $data = 2;\n}\n");

  V2("<?php class Test { var $data,$data2;}",
     "class Test {\npublic $data, $data2;\n}\n",
     "class Test {\npublic $data;\npublic $data2;\n}\n");

  V2("<?php class Test { var $data,$data2=2;}",
     "class Test {\npublic $data, $data2 = 2;\n}\n",
     "class Test {\npublic $data;\npublic $data2 = 2;\n}\n");

  V2("<?php class Test { var $data=2,$data2;}",
     "class Test {\npublic $data = 2, $data2;\n}\n",
     "class Test {\npublic $data = 2;\npublic $data2;\n}\n");

  V2("<?php class Test { var $data=2,$data2=3;}",
     "class Test {\npublic $data = 2, $data2 = 3;\n}\n",
     "class Test {\npublic $data = 2;\npublic $data2 = 3;\n}\n");

  return true;
}
//-----------------------------------------------------------------
void
InputAgent::installHandler(InputHandler *handler)
{
    if (m_handler) {
        m_handler->takePressed(NULL);
        m_handler->mouseState(V2(-1, -1), 0);
    }
    m_handler = handler;
    if (m_handler) {
        m_handler->takePressed(m_keys);
        Uint8 buttons;
        V2 mouseLoc = getMouseState(&buttons);
        m_handler->mouseState(mouseLoc, buttons);
    }
}
Beispiel #7
0
void test_op()
{
    Point_E3d  P1(3.0,4.0,5.0);
    Point_E3d  P2(4.0,7.0,9.0);
    Vector_E3d V1(8.0,4.0,2.0);

    Point_E3d A1 = P1;
    A1 += V1;
    assert( Point_E3d(11.0,8.0,7.0) == A1 );
    A1 -= V1;
    assert( P1 == A1 );

    Vector_E3d V2(P1, P2);
    assert( Vector_E3d(1.0, 3.0, 4.0) == V2 );
}
Beispiel #8
0
// note the hear flux rate have to be calculted after getkinetic energy
// this should go hand-in-hand with the temperature calculation
Array4z Analysis::getHeatFlux(int sp) 
{
    A4_z = 0.;

    Array3z V2(RxLD, RkyLD, RzLD); 
    Array3z W2(RxLD, RkyLD, RzLD); 
   
   //for(int s = ((sp == TOTAL) ? NsLlD : sp); s <= NsLuD && ((sp != TOTAL) ? s == sp : true)  ; s++) {
  // for(int s = ((sp == TOTAL) ? NsLlD : sp); (s <= ((sp == TOTAL) ? NsLuD : sp)) && ( (sp >= NsLlD) && (sp <= NsLuD))  ; s++) { 
  for(int s = NsLlD; s <= NsLuD; s++) {
      
      const double d6Z = M_PI * plasma->species(s).n0 * plasma->species(s).T0 * plasma->B0 * dv * dm * scaleXYZ;

      for(int m=NmLlD; m<= NmLuD;m++ ) { 
      
        V2 = 0.; W2 = 0.;
        // multiply in real-space 
      for(int z=NzLlD; z<= NzLuD;z++){ for(int x=NxLlD; x  <= NxLuD ;  x++) { for(int y_k=NkyLlD; y_k<= NkyLuD;y_k++) { 

            const cmplxd ky=cmplxd(0.,-fft->ky(y_k));
              
            V2(x,y_k,z) = ky * fields->phi(x,y_k,z,m,s);
        
             // integrate over velocity space
             for(int v=NvLlD; v<= NvLuD;v++) W2(x,y_k,z) += (pow2(V(v)) +  M(m) * plasma->B0) * vlasov->f(x, y_k, z, v, m, s) * d6Z;

         }}}

            A4_z(RxLD, RkyLD, RzLD,s) = fft->multiply(V2, W2, A_xyz);
     
      } }

    return parallel->collect(A4_z, OP_SUM, DIR_VM);


};
Beispiel #9
0
static void
reset_leave_nodes(struct cell *this_)
{
    if(this_ == 0)
        return;
    else if(this_->childs[0] == 0) {
        for(uint32_t i = 0; i < data.num_coeffs; i++) {
            this_->a[i] = V2(0,0);
        }
    }

    for(uint32_t i = 0; i < 4; i++) {
        reset_leave_nodes(this_->childs[i]);
    }
}
Beispiel #10
0
// preserve orientation of the most anisotropic metric !!!
SMetric3 intersection_conserve_mostaniso (const SMetric3 &m1, const SMetric3 &m2)
{
  fullMatrix<double> V1(3,3);
  fullVector<double> S1(3);
  m1.eig(V1,S1,true);
  double ratio1 = fabs(S1(0)/S1(2));  // Minimum ratio because we take sorted eigenvalues
  fullMatrix<double> V2(3,3);
  fullVector<double> S2(3);
  m2.eig(V2,S2,true);
  double ratio2 = fabs(S2(0)/S2(2));  // Minimum ratio because we take sorted eigenvalues

  if (ratio1 < ratio2)
    return intersection_conserveM1(m1, m2);
  else
    return intersection_conserveM1(m2, m1);
}
static Standard_Boolean TriangleIsValid(const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3)
{
    gp_Vec V1(P1,P2);
    gp_Vec V2(P2,P3);
    gp_Vec V3(P3,P1);

    if ((V1.SquareMagnitude() > 1.e-10) && (V2.SquareMagnitude() > 1.e-10) && (V3.SquareMagnitude() > 1.e-10)) {
        V1.Cross(V2);
        if (V1.SquareMagnitude() > 1.e-10)
            return Standard_True;
        else
            return Standard_False;
    }
    else
        return Standard_False;
}
Beispiel #12
0
Standard_Boolean Surface::triangleIsValid(const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3)
{
	gp_Vec V1(P1,P2);               // V1=(P1,P2)
	gp_Vec V2(P2,P3);               // V2=(P2,P3)
	gp_Vec V3(P3,P1);               // V3=(P3,P1)

	if ((V1.SquareMagnitude() > 1.e-10) && (V2.SquareMagnitude() > 1.e-10) && (V3.SquareMagnitude() > 1.e-10))
	{
		gp_Vec normal = V1.Crossed(V2) + V2.Crossed(V3) + V3.Crossed(V1);
		if (normal.SquareMagnitude() > 1.e-10)
			return Standard_True;
		else
			return Standard_False;
	}

	return Standard_False;
}
Beispiel #13
0
	void SmtWater::UpdateNormal()
	{
		//new mem
		Vector3 *pNormals = new Vector3[CST_INT_GRID_SIZE];

		//calculator normal
		for( int iY=0; iY<CST_INT_GRID_HEIGHT - 1; iY++ )
		{
			for(int  iX=0; iX<CST_INT_GRID_WIDTH - 1; iX++ )
			{
				int P1,P2,P3,P4;
				P1 = (iY * CST_INT_GRID_WIDTH) + iX;
				P2 = ((iY + 1) * CST_INT_GRID_WIDTH) + iX;
				P3 = P1 + 1;
				P4 = P2 + 1;

				Vector4 V1(wvertex[P1].x,wvertex[P1].y,wvertex[P1].z),
					    V2(wvertex[P2].x,wvertex[P2].y,wvertex[P2].z),
					    V3(wvertex[P3].x,wvertex[P3].y,wvertex[P3].z),
					    V4(wvertex[P4].x,wvertex[P4].y,wvertex[P4].z);

				Vector4 nor1 = GalcTriangleNormal(V1, V3, V2);
				Vector4 nor2 = GalcTriangleNormal(V3, V4, V2);

				pNormals[P1] += nor1;
				pNormals[P2] += nor1;
				pNormals[P3] += nor1;
				pNormals[P2] += nor2;
				pNormals[P3] += nor2;
				pNormals[P4] += nor2;
			}
		}

		//normalize
		for(long i=0; i < CST_INT_GRID_SIZE; i++)
		{
			pNormals[i].Normalize();
			wvertex[i].nx = pNormals[i].x;
			wvertex[i].ny = pNormals[i].y;
			wvertex[i].nz = pNormals[i].z;
		}

		SMT_SAFE_DELETE_A(pNormals);
	}
Beispiel #14
0
internal void
DEBUGTextLine(char *String) {
    debug_state *DebugState = DEBUGGetState();
    if (DebugState) {
        render_group *RenderGroup = DebugState->RenderGroup;

        loaded_font *Font = PushFont(RenderGroup, DebugState->FontID);

        if (Font) {
            hha_font *Info = GetFontInfo(RenderGroup->Assets, DebugState->FontID);

            DEBUGTextOutAt(V2(DebugState->LeftEdge,
                              DebugState->AtY - DebugState->FontScale * GetStartingBaselineY(DebugState->DebugFontInfo)), String);

            DebugState->AtY -= GetLineAdvanceFor(Info) * DebugState->FontScale;
        } else {
        }
    }
}
Beispiel #15
0
void testgammagap()
{
	unsigned int n = 512*1024+199481101;
	std::vector<uint64_t> V (n);
	std::vector<uint64_t> V2(n);
	for ( uint64_t i = 0; i < V.size(); ++i )
	{
		V[i] = i & 0xFFull;
		V2[i] = rand() % 0xFFull;
	}

	std::string const fn("tmpfile");
	std::string const fn2("tmpfile2");
	std::string const fnm("tmpfile.merged");

	::libmaus::util::TempFileRemovalContainer::setup();
	::libmaus::util::TempFileRemovalContainer::addTempFile(fn);
	::libmaus::util::TempFileRemovalContainer::addTempFile(fn2);
	::libmaus::util::TempFileRemovalContainer::addTempFile(fnm);

	::libmaus::gamma::GammaGapEncoder GGE(fn);
	GGE.encode(V.begin(),V.end());
	::libmaus::gamma::GammaGapEncoder GGE2(fn2);
	GGE2.encode(V2.begin(),V2.end());
	
	::libmaus::huffman::IndexDecoderData IDD(fn);
	
	::libmaus::gamma::GammaGapDecoder GGD(std::vector<std::string>(1,fn));
	
	bool ok = true;
	for ( uint64_t i = 0; i < n; ++i )
	{
		uint64_t const v = GGD.decode();
		ok = ok && (v == V[i]);
	}
	std::cout << "decoding " << (ok ? "ok" : "fail") << std::endl;

	std::vector < std::vector<std::string> > merin;
	merin.push_back(std::vector<std::string>(1,fn));
	merin.push_back(std::vector<std::string>(1,fn2));
	::libmaus::gamma::GammaGapEncoder::merge(merin,fnm);
}
Beispiel #16
0
/*!
 * Добавление в базу информации о версии, в будущем эта информация может быть использована для автоматического обновления схемы базы данных.
 */
void HistoryDB::version()
{
  QSqlQuery query(QSqlDatabase::database(m_id));
  query.exec(LS("PRAGMA user_version"));
  if (!query.first())
    return;

  qint64 version = query.value(0).toLongLong();
  if (!version) {
    query.exec(LS("PRAGMA user_version = 4"));
    version = 4;
    return;
  }

  query.finish();

  if (version == 1) version = V2();
  if (version == 2) version = V3();
  if (version == 3) version = V4();
}
Beispiel #17
0
void dataset::calc_dist(REALNUM_TYPE rtDef, REALNUM_TYPE metricV, UNSIGNED_1B_TYPE metricKind)
//metricKind: 0 - Euclidean, 1 - Cosine-based, 2 - Correlation coff, 3 - Tanimoto
//all coefficients are turned into distances in a way of  = 1 - (coff)^metricV
{
	UNSIGNED_4B_TYPE i, i1, j, N = patt.RowNO(), D = patt.ColNO();
	dist.SetSize(N, N);
	apvector<REALNUM_TYPE> V1(D), V2(D);
	for (i = 0; i < N; i++)
	{
		for (j = 0; j < D; j++)	V1[j] = patt(i, j);
		dist(i,i) = rtDef;
		for (i1 = i + 1; i1 < N; i1++)
		{
			for (j = 0; j < D; j++)	V2[j] = patt(i1, j);
			dist(i, i1) = dist(i1, i) = getMetricDistance(V1, V2, metricV, metricKind);
		}//for i1
	}//for i

	calc_dist_pars();
}
Beispiel #18
0
int main() {
  // refaire les tests de Darray

  // Test de Dvector par héritage

  Dvector V1(5, 3.0);
  std::cout << "V1" << std::endl;
  V1.display(std::cout);
  Dvector V2(V1);
  std::cout << "V2" << std::endl;
  V2.display(std::cout);
  Dvector V3(5);
  std::cout << "V3" << std::endl;
  V3.display(std::cout);
  Dvector V4;
  std::cout << "V4" << std::endl;
  V4.display(std::cout);

  double d = V1*V3;
  std::cout << "d = " << d << std::endl;
}
Beispiel #19
0
int get_block_size()
{
  char buf[255];
  int len,lba=0,bsize=0;

  read_capacity(&lba,&bsize);

  len=255;
  if (mode_sense(buf,&len)==0 && buf[3]>=8) {
    return V3(&buf[4+5]);
  }

  if (mode_sense10(buf,&len)==0 && V2(&buf[6])>=8) {
    return V3(&buf[8+5]);
  }

  if (read_capacity(&lba,&bsize)==0) {
    return bsize;
  }

  return -1;
}
Beispiel #20
0
//**********************************************************************************
//	
//**********************************************************************************
void	CBackground::Render()
{
	if ( s_bPBPFadeIn == true )
	{
		s_PBPFadeAlpha += 8;

		SETMAX( s_PBPFadeAlpha, 0xff );
	}
	else
	{
		s_PBPFadeAlpha -= 8;

		if ( s_PBPFadeAlpha < 0 )
		{
			SAFE_DELETE( s_pPBPIconTexture );
		}

		SETMIN( s_PBPFadeAlpha, 0x00 );
	}

	if ( s_pPBPIconTexture != NULL )
	{
		CGfx::DrawQuad( s_pPBPIconTexture, V2( 0.f, 0.f ), V2( CGfx::s_ScreenWidth, CGfx::s_ScreenHeight ), ARGB( s_PBPFadeAlpha, 0x80, 0x80, 0x80  ) );
	}

	CTexture *	p_background_texture( s_pBackgroundTexture );

	if ( CSkinManager::GetComponent( CSkinManager::SC_BACKGROUND )->GetTexture() != NULL )
	{
		p_background_texture = CSkinManager::GetComponent( CSkinManager::SC_BACKGROUND )->GetTexture();
	}

	if ( p_background_texture == NULL )
	{
		CGfx::DrawQuad( V2( 0.f, 0.f ), V2( CGfx::s_ScreenWidth, CGfx::s_ScreenHeight ), 0x00000000 );
	}
	else
	{
		CGfx::DrawQuad( p_background_texture, V2( 0.f, 0.f ), V2( CGfx::s_ScreenWidth, CGfx::s_ScreenHeight ), ARGB( 0xff - s_PBPFadeAlpha, 0xff, 0xff, 0xff ) );
	}

	for ( u32 i = 0; i < NUM_STRIPS; ++i )
	{
		RenderStrip( s_StripInfo[ i ] );
	}
}
Beispiel #21
0
/*
 * NOTE: When this function returns, we have multipole moments for all
 * cells in the tree.
 */
static void
calculate_multipoles()
{
    /* 
     * TODO: Clear all a to (0,0). We are doing this for all
     * non-leaf nodes in the upward pass already. We need a good way to do this
     * efficiently - maybe in the downward pass? For now we just use a little
     * helper function.
     */

    reset_leave_nodes(&data.root_cell);

    for(uint32_t i = 0; i < data.num_particles; i++) {
        v2 pos = data.positions[i];
        struct cell *residence = find_residence(&data.root_cell, pos);
        residence->a[0] += V2(1, 0);
        for(uint32_t k = 1; k < data.num_coeffs; k++) {
            /* TODO: make this faster (don't use pow, precompute 1/k) */
            residence->a[k] -= pow(pos - residence->center, k) / (float)k;
        }
    }

    accumulate_cell_multipoles(&data.root_cell);
}
Beispiel #22
0
int main(int argc, char *argv[])
{
	std::cout << "/////////////////////   POINT   //////////////////////////////////" << std::endl;
    Point newPoint(0,1,2);
    std::cout << "x : " << newPoint.x() << std::endl;
    std::cout << "y : " << newPoint.y() << std::endl;
    std::cout << "z : " << newPoint.z() << std::endl;
    newPoint.setY(5);
    Point pointB;
    std::cout << "y : " << pointB.y() << std::endl;

    if (! newPoint.isNotEqual(pointB))
    	std::cout << "equal" << std::endl;
    else
    	std::cout << "nonEqual" << std::endl;

	std::cout << "/////////////////////   VECTOR   //////////////////////////////////" << std::endl;

	Vector newVector, vect;
    newVector.setCoordonne(-8.0, 5.0, 6.0);
    Vector vec2(newPoint, pointB);
    Vector vec3(newVector, vec2);
    std::cout << "x2 : " << vec2.x() << std::endl;
    std::cout << "y2 : " << vec2.y() << std::endl;
    std::cout << "z2 : " << vec2.z() << std::endl;

    if (vect.vecteurNull())
    	std::cout << "vec Null" << std::endl;
    else
    	std::cout << "vec Non NUll" << std::endl;

    if (newVector.vecteurNull())
    	std::cout << "newVector Null" << std::endl;
    else
    	std::cout << "newVector Non NUll" << std::endl;

    std::cout << "dot => " << newVector.dot(vec2) << std::endl; 

    std::cout << "x3 : " << vec3.x() << std::endl;
    std::cout << "y3 : " << vec3.y() << std::endl;
    std::cout << "z3 : " << vec3.z() << std::endl;

	std::cout << "/////////////////////   RAY   //////////////////////////////////" << std::endl;

	Ray newRay(pointB,newPoint);
	std::cout << "origine : " << newRay.P0().x() << ", " << newRay.P0().y() << ", " << newRay.P0().z()<< std::endl;
	std::cout << "direction : " << newRay.P1().x() << ", " << newRay.P1().y() << ", " << newRay.P1().z() << std::endl;

	std::cout << "/////////////////////   Triangle   //////////////////////////////////" << std::endl;

	Point pointC(6,8,5);
    Point V2(0,-1,-10);
    Point V0(5,-50,59);
    Point V1(9,0,-25);
	Triangle newTriangle(V0,V1,V2);
	std::cout << "coordonnee : " << newTriangle.V0().x() << ", " << newTriangle.V1().y() << ", "<< newTriangle.V2().z() << std::endl; 

	std::cout << "/////////////////////   Point/Triangle   //////////////////////////////////" << std::endl;
	Point I;
	std::cout << newRay.P0().x() + 6 * newVector.x() << std::endl;
	std::cout << newRay.P0().y() + 6 * newVector.y() << std::endl;
	std::cout << newRay.P0().z() + 6 * newVector.z() << std::endl;
	I.setCoordonne(newRay.P0().x() + 6 * newVector.x(), newRay.P0().y() + 6 * newVector.y(), newRay.P0().z() + 6 * newVector.z());	
	std::cout << "coucou" << std::endl;

	std::cout << "/////////////////////  test intersect   //////////////////////////////////" << std::endl;

	int test;
	test = intersect3D_RayTriangle(newRay, newTriangle, I);
	std::cout << "I : " << I.x() << ", " << I.y() <<", "<< I.z() << "\n test : " << test << std::endl; 


	std::cout << "/////////////////////   VECTOR/Triangle  //////////////////////////////////" << std::endl;

	Vector newVector2(newTriangle.V0(), newTriangle.V1());

    std::cout << "x : " << newVector2.x() << std::endl;
    std::cout << "y : " << newVector2.y() << std::endl;
    std::cout << "z : " << newVector2.z() << std::endl;

    return 0;
}
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
			LPSTR lpCmdLine, int nCmdShow)
{
	WNDCLASSEX window_class = {}; 
	window_class.cbSize = sizeof(window_class);

    window_class.style = CS_HREDRAW | CS_VREDRAW;
	window_class.lpfnWndProc = WindowCallback;
    window_class.hInstance = hInstance;
    window_class.hCursor = LoadCursor(NULL, IDC_ARROW);
    window_class.lpszClassName = "WCPetroCanada";
	
	RegisterClassEx(&window_class);

	HWND window = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, "WCPetroCanada", "Game :)", WS_OVERLAPPEDWINDOW,
							     CW_USEDEFAULT, CW_USEDEFAULT,
								 1280, 720,
								 NULL, NULL, hInstance, NULL);
	
	ShowWindow(window, nCmdShow);
	UpdateWindow(window);

	RECT client_rect = {};
	GetClientRect(window, &client_rect);
	
	Framebuffer backbuffer = {};
	backbuffer.width = client_rect.right;
	backbuffer.height = client_rect.bottom;
	backbuffer.pixels = (uint32_t *)VirtualAlloc(NULL, backbuffer.width * backbuffer.height * sizeof(uint32_t ), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
	HDC window_context = GetDC(window);
	
	BITMAPINFO bitmap_info = {};
	bitmap_info.bmiHeader.biSize = sizeof(bitmap_info);
	bitmap_info.bmiHeader.biWidth = backbuffer.width;
	bitmap_info.bmiHeader.biHeight = backbuffer.height;
	bitmap_info.bmiHeader.biPlanes = 1;
	bitmap_info.bmiHeader.biBitCount = 32;
	bitmap_info.bmiHeader.biCompression = BI_RGB;
	
	LoadedBitmap player_head = LoadBitmap("petro.bmp");
	
	MSG message;
	bool open = true;
	Vector2 velocity = V2(0, 0);
	Vector2 position = V2(200, 200);
	float timestep = 1.0f; //TODO proper timestep
	
	EntityArray entities = {};
	Entity *player_entity = MakeEntity(&entities, EntityType_Player, V2(200, 200), player_head.width, player_head.height, V2(10, 10));
	MakeEntity(&entities, EntityType_Box, V2(50, 50), 100, 100);
	
	bool w_down = false;
	bool a_down = false;
	bool s_down = false;
	bool d_down = false;
	bool q_down = false;
	
	while(open)
	{
		while(PeekMessage(&message, NULL, 0,
						  0, PM_REMOVE))
		{
			if(message.message == WM_QUIT)
			{
				open = false;
			}
			else if(message.message == WM_KEYDOWN)
			{
				if(message.wParam == W_KEY_CODE)
				{
					w_down = true;
				}
				else if(message.wParam == S_KEY_CODE)
				{
					s_down = true;
				}
				else if(message.wParam == D_KEY_CODE)
				{
					d_down = true;
				}
				else if(message.wParam == A_KEY_CODE)
				{
					a_down = true;
				}
				else if(message.wParam == Q_KEY_CODE)
				{
					q_down = true;
				}
			}
			else if(message.message == WM_KEYUP)
			{
				if(message.wParam == W_KEY_CODE)
				{
					w_down = false;
				}
				else if(message.wParam == S_KEY_CODE)
				{
					s_down = false;
				}
				else if(message.wParam == D_KEY_CODE)
				{
					d_down = false;
				}
				else if(message.wParam == A_KEY_CODE)
				{
					a_down = false;
				}
				else if(message.wParam == Q_KEY_CODE)
				{
					q_down = false;
				}
			}
			
			TranslateMessage(&message);
			DispatchMessage(&message);
		}
		
		DrawRectangle(0, 0, backbuffer.width, backbuffer.height, backbuffer, V4(0.0f, 0.0f, 0.0f, 1.0f));
		DrawRectangle(100, 100, 100, 100, backbuffer, V4(position.x / (float)backbuffer.width, position.y / (float)backbuffer.height, 0.0f, 1.0f));
		DrawRectangle(100, 100, 150, 150, backbuffer, V4(0.0f, 1.0f, 0.0f, 0.25f));
		
		for(int i = 0; i < entities.count; i++)
		{
			Entity *entity = entities.entities + i;
			
			if(entity->type != EntityType_Invalid)
			{	
				Vector2 acceleration = V2(0, 0);
				
				if(entity == player_entity)
				{
					float multiplier = 1.0f;
					
					if(w_down)
					{
						acceleration = acceleration + V2(0, 1);
					}
					
					if(s_down)
					{
						acceleration = acceleration + V2(0, -1);
					}
					
					if(d_down)
					{
						acceleration = acceleration + V2(1, 0);
					}
					
					if(a_down)
					{
						acceleration = acceleration + V2(-1, 0);
					}
					
					if(q_down)
					{
						multiplier = 5.0f;
					}
					
					if(Length(acceleration) > 0)
					{
						acceleration = Normalize(acceleration) * multiplier;
					}
				}
				
				acceleration = acceleration - (entity->velocity * 0.05f);
				Vector2 new_velocity = (acceleration * timestep) + entity->velocity;
				Vector2 new_position = (acceleration * 0.5f * timestep * timestep) + (new_velocity * timestep) + GetCenter(entity->bounds);
				Rect2 collision_box = RectPosSize(new_position.x, new_position.y, GetWidth(entity->bounds), GetHeight(entity->bounds));
				bool intersects = false;
			
				for(int j = 0; j < entities.count; j++)
				{
					if(j != i)
					{
						Entity *other_entity = entities.entities + j;
						intersects = intersects || Intersect(other_entity->bounds, collision_box);
					}
				}
				
				if(!intersects)
				{
					entity->velocity = new_velocity;
					entity->bounds = RectPosSize(new_position.x, new_position.y, GetWidth(entity->bounds), GetHeight(entity->bounds));
				}
				else
				{
					entity->velocity = V2(0, 0);
				}
				
				switch(entity->type)
				{
					case EntityType_Box:
					{
						DrawRectangle(entity->bounds.min.x, entity->bounds.min.y,
									  GetWidth(entity->bounds), GetHeight(entity->bounds),
									  backbuffer, V4(1.0f, 0.0f, 0.0f, 1.0f));
					}
					break;
					
					case EntityType_Player:
					{
						float angle = GetAngle(entity->velocity);
						Direction direction = AngleToDirection(angle);
						Vector4 color = V4(1.0f, 1.0f, 1.0f, 0.0f);
						
						if(direction == Direction_Up)
						{
							color = V4(1.0f, 0.0f, 0.0f, 1.0f);
						}
						else if(direction == Direction_Down)
						{
							color = V4(1.0f, 1.0f, 0.0f, 1.0f);
						}
						else if(direction == Direction_Left)
						{
							color = V4(0.0f, 1.0f, 1.0f, 1.0f);
						}
						else if(direction == Direction_Right)
						{
							color = V4(0.0f, 1.0f, 0.0f, 1.0f);
						}
						
						char output[255];
						sprintf(output, "%f\n", angle);
						OutputDebugStringA(output);
						
						DrawRectangle(300,
									  300,
									  10, 10,
									  backbuffer, color);
						
						DrawRectangle(entity->bounds.min.x,
									  entity->bounds.min.y,
									  GetWidth(entity->bounds), GetHeight(entity->bounds),
									  backbuffer, intersects ? V4(0.5f, 0.0f, 0.0f, 0.5f) : V4(0.5f, 0.5f, 0.5f, 0.5f));
		
						DrawBitmap(entity->bounds.min.x,
								   entity->bounds.min.y,
								   GetWidth(entity->bounds), GetHeight(entity->bounds),
								   backbuffer, player_head);
					}
					break;
				}
			}
		}
		
		StretchDIBits(window_context,
					  0, 0, backbuffer.width, backbuffer.height,
					  0, 0, backbuffer.width, backbuffer.height,
					  backbuffer.pixels, &bitmap_info, DIB_RGB_COLORS, SRCCOPY);
	}
	
	return 0;
}
Vector2 GetCenter(Rect2 rect)
{
	return V2(rect.min.x + 0.5f * GetWidth(rect), rect.min.y + 0.5f * GetHeight(rect));
}
Beispiel #25
0
void
Scaler::ScaleBilinearFP(intType fromRow, int32 toRow)
{
	BBitmap* src;
	BBitmap* dest;
	intType srcW, srcH;
	intType destW, destH;
	intType x, y, i;
	ColumnDataFP* columnData;
	ColumnDataFP* cd;
	const uchar* srcBits;
	uchar* destBits;
	intType srcBPR, destBPR;
	const uchar* srcData;
	uchar* destDataRow;
	uchar* destData;
	const int32 kBPP = 4;

	src = GetSrcImage();
	dest = fScaledImage;

	srcW = src->Bounds().IntegerWidth();
	srcH = src->Bounds().IntegerHeight();
	destW = dest->Bounds().IntegerWidth();
	destH = dest->Bounds().IntegerHeight();

	srcBits = (uchar*)src->Bits();
	destBits = (uchar*)dest->Bits();
	srcBPR = src->BytesPerRow();
	destBPR = dest->BytesPerRow();

	fixed_point fpSrcW = to_fixed_point(srcW);
	fixed_point fpDestW = to_fixed_point(destW);
	fixed_point fpSrcH = to_fixed_point(srcH);
	fixed_point fpDestH = to_fixed_point(destH);

	columnData = new ColumnDataFP[destW];
	cd = columnData;
	for (i = 0; i < destW; i ++, cd++) {
		fixed_point column = to_fixed_point(i) * (long_fixed_point)fpSrcW / fpDestW;
		cd->srcColumn = from_fixed_point(column);
		cd->alpha1 = tail_value(column); // weigth for left pixel value
		cd->alpha0 = kFPOne - cd->alpha1; // weigth for right pixel value
	}

	destDataRow = destBits + fromRow * destBPR;

	for (y = fromRow; IsRunning() && y <= toRow; y ++, destDataRow += destBPR) {
		fixed_point row;
		intType srcRow;
		fixed_point alpha0, alpha1;

		if (fpDestH == 0) {
			row = 0;
		} else {
			row = to_fixed_point(y) * (long_fixed_point)fpSrcH / fpDestH;
		}
		srcRow = from_fixed_point(row);
		alpha1 = tail_value(row); // weight for row y+1
		alpha0 = kFPOne - alpha1; // weight for row y

		srcData = srcBits + srcRow * srcBPR;
		destData = destDataRow;

		// Need mult_correction for "outer" multiplication only
		#define I4(i) from_fixed_point(mult_correction(\
							(a[i] * a0 + b[i] * a1) * alpha0 + \
							(c[i] * a0 + d[i] * a1) * alpha1))
		#define V2(i) from_fixed_point(a[i] * alpha0 + c[i] * alpha1);
		#define H2(i) from_fixed_point(a[i] * a0 + b[i] * a1);

		if (y < destH) {
			fixed_point a0, a1;
			const uchar *a, *b, *c, *d;

			for (x = 0; x < destW; x ++, destData += kBPP) {
				a = srcData + columnData[x].srcColumn * kBPP;
				b = a + kBPP;
				c = a + srcBPR;
				d = c + kBPP;

				a0 = columnData[x].alpha0;
				a1 = columnData[x].alpha1;

				destData[0] = I4(0);
				destData[1] = I4(1);
				destData[2] = I4(2);
				destData[3] = I4(3);
			}

			// right column
			a = srcData + srcW * kBPP;
			c = a + srcBPR;

			destData[0] = V2(0);
			destData[1] = V2(1);
			destData[2] = V2(2);
			destData[3] = V2(3);
		} else {
			fixed_point a0, a1;
			const uchar *a, *b;
			for (x = 0; x < destW; x ++, destData += kBPP) {
				a = srcData + columnData[x].srcColumn * kBPP;
				b = a + kBPP;

				a0 = columnData[x].alpha0;
				a1 = columnData[x].alpha1;

				destData[0] = H2(0);
				destData[1] = H2(1);
				destData[2] = H2(2);
				destData[3] = H2(3);
			}

			// bottom, right pixel
			a = srcData + srcW * kBPP;

			destData[0] = a[0];
			destData[1] = a[1];
			destData[2] = a[2];
			destData[3] = a[3];
		}

	}

	delete[] columnData;
}
Beispiel #26
0
void testgammarl()
{
	srand(time(0));
	unsigned int n = 128*1024*1024;
	unsigned int n2 = 64*1024*1024;
	std::vector<uint64_t> V (n);
	std::vector<uint64_t> V2 (n2);
	std::vector<uint64_t> Vcat;
	unsigned int const albits = 3;
	uint64_t const almask = (1ull << albits)-1;
	
	for ( uint64_t i = 0; i < V.size(); ++i )
	{
		V[i]  = rand() & almask;
		Vcat.push_back(V[i]);
	}
	for ( uint64_t i = 0; i < V2.size(); ++i )
	{
		V2[i] = rand() & almask;
		Vcat.push_back(V2[i]);
	}

	std::string const fn("tmpfile");
	std::string const fn2("tmpfile2");
	std::string const fn3("tmpfile3");
	::libmaus::util::TempFileRemovalContainer::setup();
	::libmaus::util::TempFileRemovalContainer::addTempFile(fn);
	::libmaus::util::TempFileRemovalContainer::addTempFile(fn2);
	::libmaus::util::TempFileRemovalContainer::addTempFile(fn3);

	::libmaus::gamma::GammaRLEncoder GE(fn,albits,V.size(),256*1024);	
	for ( uint64_t i = 0; i < V.size(); ++i )
		GE.encode(V[i]);
	GE.flush();

	::libmaus::gamma::GammaRLEncoder GE2(fn2,albits,V2.size(),256*1024);
	for ( uint64_t i = 0; i < V2.size(); ++i )
		GE2.encode(V2[i]);
	GE2.flush();

	#if 0
	::libmaus::huffman::IndexDecoderData IDD(fn);
	for ( uint64_t i = 0; i < IDD.numentries+1; ++i )
		std::cerr << IDD.readEntry(i) << std::endl;	
	#endif

	::libmaus::gamma::GammaRLDecoder GD(std::vector<std::string>(1,fn));
	assert ( GD.getN() == n );

	for ( uint64_t i = 0; i < n; ++i )
		assert ( GD.decode() == static_cast<int64_t>(V[i]) );
	
	uint64_t const off = n / 2 + 1031;
	::libmaus::gamma::GammaRLDecoder GD2(std::vector<std::string>(1,fn),off);
	for ( uint64_t i = off; i < n; ++i )
		assert ( GD2.decode() == static_cast<int64_t>(V[i]) );
		
	std::vector<std::string> fnv;
	fnv.push_back(fn);
	fnv.push_back(fn2);
	::libmaus::gamma::GammaRLEncoder::concatenate(fnv,fn3);
	
	for ( uint64_t off = 0; off < Vcat.size(); off += 18521 )
	{
		::libmaus::gamma::GammaRLDecoder GD3(std::vector<std::string>(1,fn3),off);	
		assert ( GD3.getN() == Vcat.size() );
		
		for ( uint64_t i = 0; i < std::min(static_cast<uint64_t>(1024ull),Vcat.size()-off); ++i )
			assert ( GD3.decode() == static_cast<int64_t>(Vcat[off+i]) );
	}

	remove ( fn.c_str() );
	remove ( fn2.c_str() );
	remove ( fn3.c_str() );	
}
//=======================================================================
//function : HasIntersection3
//purpose  : Auxilare for HasIntersection()
//           find intersection point between triangle (P1,P2,P3)
//           and segment [PC,P]
//=======================================================================
static bool HasIntersection3(const gp_Pnt& P, const gp_Pnt& PC, gp_Pnt& Pint,
                             const gp_Pnt& P1, const gp_Pnt& P2, const gp_Pnt& P3)
{
  //cout<<"HasIntersection3"<<endl;
  //cout<<"  PC("<<PC.X()<<","<<PC.Y()<<","<<PC.Z()<<")"<<endl;
  //cout<<"  P("<<P.X()<<","<<P.Y()<<","<<P.Z()<<")"<<endl;
  //cout<<"  P1("<<P1.X()<<","<<P1.Y()<<","<<P1.Z()<<")"<<endl;
  //cout<<"  P2("<<P2.X()<<","<<P2.Y()<<","<<P2.Z()<<")"<<endl;
  //cout<<"  P3("<<P3.X()<<","<<P3.Y()<<","<<P3.Z()<<")"<<endl;
  gp_Vec VP1(P1,P2);
  gp_Vec VP2(P1,P3);
  IntAna_Quadric IAQ(gp_Pln(P1,VP1.Crossed(VP2)));
  IntAna_IntConicQuad IAICQ(gp_Lin(PC,gp_Dir(gp_Vec(PC,P))),IAQ);
  if(IAICQ.IsDone()) {
    if( IAICQ.IsInQuadric() )
      return false;
    if( IAICQ.NbPoints() == 1 ) {
      gp_Pnt PIn = IAICQ.Point(1);
      double preci = 1.e-6;
      // check if this point is internal for segment [PC,P]
      bool IsExternal =
        ( (PC.X()-PIn.X())*(P.X()-PIn.X()) > preci ) ||
        ( (PC.Y()-PIn.Y())*(P.Y()-PIn.Y()) > preci ) ||
        ( (PC.Z()-PIn.Z())*(P.Z()-PIn.Z()) > preci );
      if(IsExternal) {
        return false;
      }
      // check if this point is internal for triangle (P1,P2,P3)
      gp_Vec V1(PIn,P1);
      gp_Vec V2(PIn,P2);
      gp_Vec V3(PIn,P3);
      if( V1.Magnitude()<preci || V2.Magnitude()<preci ||
          V3.Magnitude()<preci ) {
        Pint = PIn;
        return true;
      }
      gp_Vec VC1 = V1.Crossed(V2);
      gp_Vec VC2 = V2.Crossed(V3);
      gp_Vec VC3 = V3.Crossed(V1);
      if(VC1.Magnitude()<preci) {
        if(VC2.IsOpposite(VC3,preci)) {
          return false;
        }
      }
      else if(VC2.Magnitude()<preci) {
        if(VC1.IsOpposite(VC3,preci)) {
          return false;
        }
      }
      else if(VC3.Magnitude()<preci) {
        if(VC1.IsOpposite(VC2,preci)) {
          return false;
        }
      }
      else {
        if( VC1.IsOpposite(VC2,preci) || VC1.IsOpposite(VC3,preci) ||
            VC2.IsOpposite(VC3,preci) ) {
          return false;
        }
      }
      Pint = PIn;
      return true;
    }
  }

  return false;
}
Beispiel #28
0
  void 
  RTriangleMesh::init(const std::tr1::shared_ptr<magnet::thread::TaskQueue>& systemQueue)
  {
    RTriangles::init(systemQueue);

    //Send the data we already have
    setGLPositions(_vertices);
    setGLElements(_elements);

    {//Calculate the normal vectors
      std::vector<float> VertexNormals(_vertices.size(), 0);
    
      //For every triangle, add the cross product of the two edges. We
      //then renormalize the normal to get a
      //"weighted-by-the-triangle-size" normal.
    
      for (size_t triangle(0); triangle < _elements.size() / 3; ++triangle)
	{
	  //Grab the vertex IDs
	  size_t v1(_elements[3 * triangle + 0]),
	    v2(_elements[3 * triangle + 1]),
	    v3(_elements[3 * triangle + 2]);
	
	  Vector V1(_vertices[3 * v1 + 0],
		    _vertices[3 * v1 + 1],
		    _vertices[3 * v1 + 2]),
	    V2(_vertices[3 * v2 + 0],
	       _vertices[3 * v2 + 1],
	       _vertices[3 * v2 + 2]),
	    V3(_vertices[3 * v3 + 0],
	       _vertices[3 * v3 + 1],
	       _vertices[3 * v3 + 2]);

	  Vector norm = (V2-V1)^(V3-V2);
	
	  for (size_t i(0); i < 3; ++i)
	    {
	      VertexNormals[3 * v1 + i] += norm[i];
	      VertexNormals[3 * v2 + i] += norm[i];
	      VertexNormals[3 * v3 + i] += norm[i];
	    }
	}

      //Now normalize those vertices
      for (size_t vert(0); vert < _vertices.size() / 3; ++vert)
	{
	  double norm 
	    = VertexNormals[3 * vert + 0] * VertexNormals[3 * vert + 0]
	    + VertexNormals[3 * vert + 1] * VertexNormals[3 * vert + 1]
	    + VertexNormals[3 * vert + 2] * VertexNormals[3 * vert + 2];
	
	  if (norm)
	    {
	      double factor = 1 / std::sqrt(norm);
	      VertexNormals[3 * vert + 0] *= factor;
	      VertexNormals[3 * vert + 1] *= factor;
	      VertexNormals[3 * vert + 2] *= factor;
	    }
	  else
	    {
	      VertexNormals[3 * vert + 0] = 1;
	      VertexNormals[3 * vert + 1] = 0;
	      VertexNormals[3 * vert + 2] = 0;
	    }
	}

      setGLNormals(VertexNormals);
    }
  
    //Reclaim some memory
    _vertices.clear();
    _elements.clear();
  }
Beispiel #29
0
 template<typename MT, typename VT> class mat_vec_mul_lazy;
 
 ///
 template<typename MT, typename VT> mat_vec_mul_lazy<MT,VT> mat_vec_mul (MT const & a, VT const & b) { return mat_vec_mul_lazy<MT,VT>(a,b); }
 
 // ----------------- implementation -----------------------------------------
 
 template<typename MT, typename VT> 
  class mat_vec_mul_lazy :  TRIQS_MODEL_CONCEPT(ImmutableVector) { 

   typedef typename MT::value_type V1;
   typedef typename VT::value_type V2;
   static_assert((boost::is_same<V1,V2>::value),"Different values : not implemented");

   public:
   typedef BOOST_TYPEOF_TPL( V1() * V2()) value_type;
   typedef typename VT::domain_type  domain_type;
   typedef typename const_view_type_if_exists_else_type<MT>::type M_type;
   typedef typename const_view_type_if_exists_else_type<VT>::type V_type;
   const M_type M; const V_type V;

   private: 
   typedef vector<value_type> vector_type;

   struct internal_data {
    vector_type R;
    internal_data(mat_vec_mul_lazy const & P): R( P.a.size(), P.b.dim1()) {
     const_qcache<M_type> Cm(P.M); const_qcache<V_type> Cv(P.V);
     boost::numeric::bindings::blas::gemv(1, Cm(), Cv(), 0, R);
    }
   };
  Basis_HDIV_TRI_In_FEM<Scalar,ArrayScalar>::Basis_HDIV_TRI_In_FEM( const int n ,
                                                                    const EPointType pointType ):
    Phis( n ),
    coeffs( (n+1)*(n+2) , n*(n+2) )
  {
    const int N = n*(n+2);
    this -> basisCardinality_  = N;
    this -> basisDegree_       = n;
    this -> basisCellTopology_ = shards::CellTopology(shards::getCellTopologyData<shards::Triangle<3> >() );
    this -> basisType_         = BASIS_FEM_FIAT;
    this -> basisCoordinates_  = COORDINATES_CARTESIAN;
    this -> basisTagsAreSet_   = false;


    const int littleN = n*(n+1);   // dim of (P_{n-1})^2 -- smaller space
    const int bigN = (n+1)*(n+2);  // dim of (P_{n})^2 -- larger space
    const int scalarSmallestN = (n-1)*n / 2;
    const int scalarLittleN = littleN/2;
    const int scalarBigN = bigN/2;

    // first, need to project the basis for RT space onto the
    // orthogonal basis of degree n
    // get coefficients of PkHx

    Teuchos::SerialDenseMatrix<int,Scalar> V1(bigN, N);

    // basis for the space is 
    // { (phi_i,0) }_{i=0}^{scalarLittleN-1} ,
    // { (0,phi_i) }_{i=0}^{scalarLittleN-1} ,
    // { (x,y) . phi_i}_{i=scalarLittleN}^{scalarBigN-1}
    // columns of V1 are expansion of this basis in terms of the basis
    // for P_{n}^2

    // these two loops get the first two sets of basis functions
    for (int i=0;i<scalarLittleN;i++) {
      V1(i,i) = 1.0;
      V1(scalarBigN+i,scalarLittleN+i) = 1.0;
    }

    // now I need to integrate { (x,y) phi } against the big basis
    // first, get a cubature rule.
    CubatureDirectTriDefault<Scalar,ArrayScalar > myCub( 2 * n );
    ArrayScalar cubPoints( myCub.getNumPoints() , 2 );
    ArrayScalar cubWeights( myCub.getNumPoints() );
    myCub.getCubature( cubPoints , cubWeights );

    // tabulate the scalar orthonormal basis at cubature points
    ArrayScalar phisAtCubPoints( scalarBigN , myCub.getNumPoints() );
    Phis.getValues( phisAtCubPoints , cubPoints , OPERATOR_VALUE );

    // now do the integration
    for (int i=0;i<n;i++) {
      for (int j=0;j<scalarBigN;j++) { // int (x,y) phi_i \cdot (phi_j,0)
        V1(j,littleN+i) = 0.0;
        for (int k=0;k<myCub.getNumPoints();k++) {
          V1(j,littleN+i) += 
            cubWeights(k) * cubPoints(k,0) 
            * phisAtCubPoints(scalarSmallestN+i,k) 
            * phisAtCubPoints(j,k);
        }
      }
      for (int j=0;j<scalarBigN;j++) {  // int (x,y) phi_i \cdot (0,phi_j)
        V1(j+scalarBigN,littleN+i) = 0.0;
        for (int k=0;k<myCub.getNumPoints();k++) {
          V1(j+scalarBigN,littleN+i) += 
            cubWeights(k) * cubPoints(k,1) 
            * phisAtCubPoints(scalarSmallestN+i,k) 
            * phisAtCubPoints(j,k);
        }
      }
    }

    //std::cout << V1 << "\n";

    
    // next, apply the RT nodes (rows) to the basis for (P_n)^2 (columns)
    Teuchos::SerialDenseMatrix<int,Scalar> V2(N , bigN);

    // first 3 * degree nodes are normals at each edge
    // get the points on the line
    ArrayScalar linePts( n , 1 );
    if (pointType == POINTTYPE_WARPBLEND) {
      CubatureDirectLineGauss<Scalar> edgeRule( n );
      ArrayScalar edgeCubWts( n );
      edgeRule.getCubature( linePts , edgeCubWts );
    }
    else if (pointType == POINTTYPE_EQUISPACED ) {
      shards::CellTopology linetop(shards::getCellTopologyData<shards::Line<2> >() );

      PointTools::getLattice<Scalar,ArrayScalar >( linePts , 
                                                              linetop ,
                                                              n+1 , 1 ,
                                                              POINTTYPE_EQUISPACED );
    }
    // holds the image of the line points 
    ArrayScalar edgePts( n , 2 );
    ArrayScalar phisAtEdgePoints( scalarBigN , n );

    // these are scaled by the appropriate edge lengths.
    const Scalar nx[] = {0.0,1.0,-1.0};
    const Scalar ny[] = {-1.0,1.0,0.0};
    
    for (int i=0;i<3;i++) {  // loop over edges
      CellTools<Scalar>::mapToReferenceSubcell( edgePts ,
                                                linePts ,
                                                1 ,
                                                i ,
                                                this->basisCellTopology_ );

      Phis.getValues( phisAtEdgePoints , edgePts , OPERATOR_VALUE );

      // loop over points (rows of V2)
      for (int j=0;j<n;j++) {
        // loop over orthonormal basis functions (columns of V2)
        for (int k=0;k<scalarBigN;k++) {
          V2(n*i+j,k) = nx[i] * phisAtEdgePoints(k,j);
          V2(n*i+j,k+scalarBigN) = ny[i] * phisAtEdgePoints(k,j);
        }
      }
    }

    // next map the points to each edge


    // remaining nodes are divided into two pieces:  point value of x
    // components and point values of y components.  These are
    // evaluated at the interior of a lattice of degree + 1, For then
    // the degree == 1 space corresponds classicaly to RT0 and so gets
    // no internal nodes, and degree == 2 corresponds to RT1 and needs
    // one internal node per vector component.
    const int numInternalPoints = PointTools::getLatticeSize( this->getBaseCellTopology() ,
                                                              n + 1 ,
                                                              1 );

    if (numInternalPoints > 0) {
      ArrayScalar internalPoints( numInternalPoints , 2 );
      PointTools::getLattice<Scalar,ArrayScalar >( internalPoints ,
                                                              this->getBaseCellTopology() , 
                                                              n + 1 ,
                                                              1 ,
                                                              pointType );
      
      ArrayScalar phisAtInternalPoints( scalarBigN , numInternalPoints );
      Phis.getValues( phisAtInternalPoints , internalPoints , OPERATOR_VALUE );
      
      // copy values into right positions of V2
      for (int i=0;i<numInternalPoints;i++) {
        for (int j=0;j<scalarBigN;j++) {
          // x component
          V2(3*n+i,j) = phisAtInternalPoints(j,i);
          // y component
          V2(3*n+numInternalPoints+i,scalarBigN+j) = phisAtInternalPoints(j,i);
        }
      }
    }
//     std::cout << "Nodes on big basis\n";
//     std::cout << V2 << "\n";
//     std::cout << "End nodes\n";

    Teuchos::SerialDenseMatrix<int,Scalar> Vsdm( N , N );

    // multiply V2 * V1 --> V
    Vsdm.multiply( Teuchos::NO_TRANS , Teuchos::NO_TRANS , 1.0 , V2 , V1 , 0.0 );

//     std::cout << "Vandermonde:\n";
//     std::cout << Vsdm << "\n";
//     std::cout << "End Vandermonde\n";
    
    Teuchos::SerialDenseSolver<int,Scalar> solver;
    solver.setMatrix( rcp( &Vsdm , false ) );
    solver.invert( );

    Teuchos::SerialDenseMatrix<int,Scalar> Csdm( bigN , N );
    Csdm.multiply( Teuchos::NO_TRANS , Teuchos::NO_TRANS , 1.0 , V1 , Vsdm , 0.0 );

    //    std::cout << Csdm << "\n";

    for (int i=0;i<bigN;i++) {
      for (int j=0;j<N;j++) {
        coeffs(i,j) = Csdm(i,j);
      }
    }
  }