Beispiel #1
0
dMatrix clSpline::GetCoordinates(const double uSpec)
{
  dMatrix uDummy(1, 1);
  uDummy.SetElement(1, 1, uSpec);

  return(GetCoordinates(uDummy));
}
Beispiel #2
0
void CKey::Repaint()
{
    if (!toolkit)
    {
        return;
    }
    oxeCoords coords;
    GetCoordinates(&coords);
    toolkit->CopyRect(coords.destX, coords.destY, coords.width, coords.height, coords.origBmp, coords.origX, coords.origY);
}
InfoForDisplay DisplayableObject::GetInfoForDisplay()
{
	InfoForDisplay info;
	info.id = m_id;
	info.name = m_name;
	info.state = m_state;
	info.coordinates = GetCoordinates();
	info.reverse = m_reverseSprite;
	return info;
}
vtkRectilinearGrid *
CreateGrid(const double *bounds, int numX, int numY, int numZ, int minX,
           int maxX, int minY, int maxY, bool cellCenteredOutput, bool is3D)
{
    vtkDataArray *xc = NULL;
    vtkDataArray *yc = NULL;
    vtkDataArray *zc = NULL;

    double width  = bounds[1] - bounds[0];
    double height = bounds[3] - bounds[2];
    double depth  = bounds[5] - bounds[4];

    int numX2 = (cellCenteredOutput ? numX+1 : numX);
    int maxX2 = (cellCenteredOutput ? maxX+1 : maxX);
    xc = GetCoordinates(bounds[0], width, numX2, minX, maxX2);
    int numY2 = (cellCenteredOutput ? numY+1 : numY);
    int maxY2 = (cellCenteredOutput ? maxY+1 : maxY);
    yc = GetCoordinates(bounds[2], height, numY2, minY, maxY2);
    if (is3D)
    {
        int numZ2 = (cellCenteredOutput ? numZ+1 : numZ);
        zc = GetCoordinates(bounds[4], depth, numZ2, 0, numZ2);
    }
    else
    {
        zc = GetCoordinates(bounds[4], depth, 1, 0, 1);
    }

    vtkRectilinearGrid *rv = vtkRectilinearGrid::New();
    if (cellCenteredOutput)
        rv->SetDimensions(maxX-minX+1, maxY-minY+1, is3D ? numZ+1 : 1);
    else
        rv->SetDimensions(maxX-minX, maxY-minY, numZ);
    rv->SetXCoordinates(xc);
    xc->Delete();
    rv->SetYCoordinates(yc);
    yc->Delete();
    rv->SetZCoordinates(zc);
    zc->Delete();

    return rv;
}
Beispiel #5
0
void CChannels::Repaint()
{
    if (!toolkit)
    {
        return;
    }
    oxeCoords coords[MIDICHANNELS];
    oxeCoords *c = coords;
    int count = GetCoordinates(c);
    while (count--)
    {
        toolkit->CopyRect(c->destX, c->destY, c->width, c->height, c->origBmp, c->origX, c->origY);
        c++;
    }
}
Beispiel #6
0
/*
@param cellId id of the cell the particle is in
@param id id of the particle
@return list iterator of a list of nearest neighbours
*/
list<unsigned int>::iterator CellSubdivision::GetNeighbours(const unsigned int cellId, const unsigned int id){
    m_neighbours.clear();

    int x,y;
    int a,b;
    GetCoordinates(cellId, x, y);

    set<unsigned int>::iterator it;

    for (int i = x-1; i<x+2; i++)
        for (int j = y-1; j<y+2; j++){
            a = i;
            b = j;
            NormaliseCoordinates(a,b);
            for (it=m_cells[GetCell(a,b)].begin(); it!=m_cells[GetCell(a,b)].end(); it++)
                if (*it!=id) m_neighbours.push_back(*it);
        }

    return m_neighbours.begin();
}
Beispiel #7
0
bool clNode::IsEqual(const clNode &source) const
{
  bool isEqual = true; // 0 = not equal; 1 = equal

  try
  {
    /*
    ** Does not check for nodeID
    */

    dMatrix coordA = GetCoordinates();
    dMatrix coordB = source.GetCoordinates();

    if(coordA.GetNumberRows() == coordB.GetNumberRows())
    {
      for(int r=0; r<coordA.GetNumberRows() && isEqual; r++)
      {
        if(fabs(coordA(r+1, 1) - coordB(r+1, 1)) > CLIPRANGE)
        {
          isEqual = isEqual && false;
        }
      }
    }

//    if(isEqual)
//    {
//      cout << "IDENTICAL NODES: [" << GetNodeID() << ", " << source.GetNodeID() << "]" << endl;
//    }
  }

  catch(clExceptionTree EX)
  {
    EX.AddMethodToTree("clNode::IsEqual");
    throw EX;
  }

  return(isEqual);
}
Beispiel #8
0
void ConsoleListener::PixelSpace(int Left, int Top, int Width, int Height, bool Resize)
{
#ifdef _WIN32
	// Check size
	if (Width < 8 || Height < 12) return;

	bool DBef = true;
	bool DAft = true;
	std::string SLog = "";

	const HWND hWnd = GetConsoleWindow();
	const HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

	// Get console info
	CONSOLE_SCREEN_BUFFER_INFO ConInfo;
	GetConsoleScreenBufferInfo(hConsole, &ConInfo);
	DWORD BufferSize = ConInfo.dwSize.X * ConInfo.dwSize.Y;

	// ---------------------------------------------------------------------
	//  Save the current text
	// ------------------------
	DWORD cCharsRead = 0;
	COORD coordScreen = { 0, 0 };

	static const int MAX_BYTES = 1024 * 16;

	std::vector<std::array<CHAR, MAX_BYTES>> Str;
	std::vector<std::array<WORD, MAX_BYTES>> Attr;

	// ReadConsoleOutputAttribute seems to have a limit at this level
	static const int ReadBufferSize = MAX_BYTES - 32;

	DWORD cAttrRead = ReadBufferSize;
	DWORD BytesRead = 0;
	while (BytesRead < BufferSize)
	{
		Str.resize(Str.size() + 1);
		if (!ReadConsoleOutputCharacter(hConsole, Str.back().data(), ReadBufferSize, coordScreen, &cCharsRead))
			SLog += StringFromFormat("WriteConsoleOutputCharacter error");

		Attr.resize(Attr.size() + 1);
		if (!ReadConsoleOutputAttribute(hConsole, Attr.back().data(), ReadBufferSize, coordScreen, &cAttrRead))
			SLog += StringFromFormat("WriteConsoleOutputAttribute error");

		// Break on error
		if (cAttrRead == 0) break;
		BytesRead += cAttrRead;
		coordScreen = GetCoordinates(BytesRead, ConInfo.dwSize.X);
	}
	// Letter space
	int LWidth = (int)(floor((float)Width / 8.0f) - 1.0f);
	int LHeight = (int)(floor((float)Height / 12.0f) - 1.0f);
	int LBufWidth = LWidth + 1;
	int LBufHeight = (int)floor((float)BufferSize / (float)LBufWidth);
	// Change screen buffer size
	LetterSpace(LBufWidth, LBufHeight);


	ClearScreen(true);	
	coordScreen.Y = 0;
	coordScreen.X = 0;
	DWORD cCharsWritten = 0;

	int BytesWritten = 0;
	DWORD cAttrWritten = 0;
	for (size_t i = 0; i < Attr.size(); i++)
	{
		if (!WriteConsoleOutputCharacter(hConsole, Str[i].data(), ReadBufferSize, coordScreen, &cCharsWritten))
			SLog += StringFromFormat("WriteConsoleOutputCharacter error");
		if (!WriteConsoleOutputAttribute(hConsole, Attr[i].data(), ReadBufferSize, coordScreen, &cAttrWritten))
			SLog += StringFromFormat("WriteConsoleOutputAttribute error");

		BytesWritten += cAttrWritten;
		coordScreen = GetCoordinates(BytesWritten, LBufWidth);
	}	

	const int OldCursor = ConInfo.dwCursorPosition.Y * ConInfo.dwSize.X + ConInfo.dwCursorPosition.X;
	COORD Coo = GetCoordinates(OldCursor, LBufWidth);
	SetConsoleCursorPosition(hConsole, Coo);

	if (SLog.length() > 0) Log(LogTypes::LNOTICE, SLog.c_str());

	// Resize the window too
	if (Resize) MoveWindow(GetConsoleWindow(), Left,Top, (Width + 100),Height, true);
#endif
}
Beispiel #9
0
int main(void)
{
    unsigned char bmButtons = 0;

    TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);
    printf("-- USB Device HID Mouse Project %s --\n\r", SOFTPACK_VERSION);
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

    // SPP +
    int i;

    button_flag = 0;

    //Enable RESET
    m_pRSTC->RSTC_RCR = 0xA5000008;
    m_pRSTC->RSTC_RMR = 0xA5000001;
    Delay(1000);

    // Init USB device
    //AT91F_USB_Open();

    // Configure the RTT:
    *AT91C_RTTC_RTMR = BUTTON_SAMPLING;

    // Set in PIO mode and Configure in Input
    //AT91F_PIOA_CfgPMC();

    // InitMAM
    InitMMA();

    // InitADC
    ADCInit();

    // UART0 Init
    InitUSART0();

    // Stat led
    s_pPio->PIO_PER   = BIT31;
    // Configure PA31 as output
    s_pPio->PIO_OER   = BIT31;
    // Set PA31 to HIGH
    s_pPio->PIO_SODR  = BIT31;


    // Test flash
    if(TestFlash()) 
    {
      for(i=0; i<20; i++) 
      {
        s_pPio->PIO_CODR  = BIT31; Delay(150000);
        s_pPio->PIO_SODR  = BIT31; Delay(150000);
      }
    }

    // Button
    // Configure P20 as input
    s_pPio->PIO_ODR   = BIT20;
    // Enable
    s_pPio->PIO_PER   = BIT20;

    Delay(1000);

    // CALIBRATE WHEN BUTT IS PRESS
    // while((s_pPio->PIO_PDSR&BIT20)==BIT20);

    Delay(1000);
    // SPP -

    // If they are present, configure Vbus & Wake-up pins
    PIO_InitializeInterrupts(0);

    WAKEUP_CONFIGURE();

    // If there is on board power, switch it off
  #ifdef PIN_USB_POWER_ENB
  { const Pin pinUsbPwr = PIN_USB_POWER_ENB;
    PIO_Configure(&pinUsbPwr, 1);
  }
  #endif

    // Initialize key statuses and configure push buttons
#if defined(at91cap9dk)
    const Pin pinRow0 = PIN_KEYBOARD_ROW0;
    PIO_Configure(&pinRow0, 1);
#endif       
    PIO_Configure(pinsJoystick, PIO_LISTSIZE(pinsJoystick));

    // HID driver initialization
    HIDDMouseDriver_Initialize();

    // connect if needed
    VBUS_CONFIGURE();
    
    // Infinite loop
    while (1) 
    {
       // SPP +
       #define TIMEOUT  100
       static int Timeout = TIMEOUT;
        GetCoordinates();
        base_y = Coordinates[0]/NSAMPLE;
        base_x = Coordinates[1]/NSAMPLE;
        base_z = Coordinates[2]/NSAMPLE;
       // SPP -

        if( USBState == STATE_SUSPEND ) 
        {
            TRACE_DEBUG("suspend  !\n\r");
            USBState = STATE_IDLE;
            LowPowerMode();
        }
        if( USBState == STATE_RESUME ) 
        {
            // Return in normal MODE
            NormalPowerMode();
            USBState = STATE_IDLE;
            TRACE_DEBUG("resume !\n\r");
        }
        if (USBD_GetState() < USBD_STATE_CONFIGURED)
            continue;

        if (!Timeout)
        {
        
            unsigned char status;

            do 
            {
               status = HIDDMouseDriver_ChangePoints(bmButtons, base_x, base_y);
            }
            while (status != USBD_STATUS_SUCCESS);
            Timeout = TIMEOUT;
        }
        else
           Timeout--;
        
    }
}
/* Do several element things at once
    Load number of nodes into numnds
    Load node numbers into nds[1]...
    Load shape functions into fn[1]...
    Load shape function derviatives into xDeriv[1]..., yDeriv[1]..., zDeriv[1]...
        For axisymmetric load zDeriv with shape function / particle radial position
        Input zDeriv must not be NULL
    Input: pointer to material point dimensionless position
   NOTE: This is called at various places in the time step when gradients are needed. It should
    recalculate the ones found at the beginning of the time step using the precalculated xipos
    or CPDI info, which are found in the initialization task
   throws CommonException() if too many CPDI nodes
*/
void ElementBase::GetShapeGradients(int *numnds,double *fn,int *nds,
                                    double *xDeriv,double *yDeriv,double *zDeriv,MPMBase *mpmptr) const
{
    Vector lp;
    
    switch(useGimp)
    {   case POINT_GIMP:
        	// load nodal numbers
            GetNodes(numnds,nds);
            
            // special case for regular mesh
            if(mpmgrid.GetCartesian()>0)
                ShapeFunction(mpmptr->GetNcpos(),TRUE,&fn[1],&xDeriv[1],&yDeriv[1],&zDeriv[1]);
            else
            {	// Load element coordinates
                Vector ce[MaxElNd];
                double fnh[MaxElNd];
                GetCoordinates(ce,*numnds,nds);
                
                // find shape functions and derviatives
                ShapeFunction(mpmptr->GetNcpos(),BMATRIX,&fn[1],&xDeriv[1],&yDeriv[1],&ce[1],NULL,NULL,&fnh[1]);
            }
            break;
            
        case UNIFORM_GIMP:
        {	// uGIMP analysis
            int ndIDs[maxShapeNodes];
            Vector *xipos = mpmptr->GetNcpos();
            mpmptr->GetDimensionlessSize(lp);
            GetGimpNodes(numnds,nds,ndIDs,xipos,lp);
            GimpShapeFunction(xipos,*numnds,ndIDs,TRUE,&fn[1],&xDeriv[1],&yDeriv[1],&zDeriv[1],lp);
            GimpCompact(numnds,nds,fn,xDeriv,yDeriv,zDeriv);
            break;
        }
            
        case UNIFORM_GIMP_AS:
        {	// uGIMP analysis
            int ndIDs[maxShapeNodes];
            Vector *xipos = mpmptr->GetNcpos();
            mpmptr->GetDimensionlessSize(lp);
            GetGimpNodes(numnds,nds,ndIDs,xipos,lp);
            GimpShapeFunctionAS(xipos,*numnds,ndIDs,TRUE,&fn[1],&xDeriv[1],&yDeriv[1],&zDeriv[1],lp);
            GimpCompact(numnds,nds,fn,xDeriv,yDeriv,zDeriv);
            break;
        }
            
        case LINEAR_CPDI:
		case LINEAR_CPDI_AS:
		case QUADRATIC_CPDI:
        {   if(theMaterials[mpmptr->MatID()]->Rigid())
			{	int ndIDs[maxShapeNodes];
                Vector *xipos = mpmptr->GetNcpos();
                mpmptr->GetDimensionlessSize(lp);
                GetGimpNodes(numnds,nds,ndIDs,xipos,lp);
                if(fmobj->IsAxisymmetric())
                    GimpShapeFunctionAS(xipos,*numnds,ndIDs,TRUE,&fn[1],&xDeriv[1],&yDeriv[1],&zDeriv[1],lp);
                else
					GimpShapeFunction(xipos,*numnds,ndIDs,TRUE,&fn[1],&xDeriv[1],&yDeriv[1],&zDeriv[1],lp);
				GimpCompact(numnds,nds,fn,xDeriv,yDeriv,zDeriv);
            }
            else
            {   *numnds = GetCPDIFunctions(nds,fn,xDeriv,yDeriv,zDeriv,mpmptr);
            }
            break;
		}
    }
}
Beispiel #11
0
//*--------------------------------------------------------------------------------------
//* Function Name       : main
//* Object              :
//*--------------------------------------------------------------------------------------
int main ( void )
{
//    char button = 0;
//    int x = 0, y = 0, j = 0;
//    int adc;
//    int i = 0;
    int x,y,z,i;

    button_flag = 0;

    //Init trace DBGU
    //AT91F_DBGU_Init();
    //AT91F_DBGU_Printk("\n\r-I- BasicUSB 1.1 (USB_DP_PUP) \n\r0) Set Pull-UP 1) Clear Pull UP\n\r");

    //Enable RESET
    m_pRSTC->RSTC_RCR = 0xA5000008;
    m_pRSTC->RSTC_RMR = 0xA5000001;
    Delay(1000);

    // Init USB device
    AT91F_USB_Open();

    // Configure the RTT:
    *AT91C_RTTC_RTMR = BUTTON_SAMPLING;

    // Set in PIO mode and Configure in Input
    AT91F_PIOA_CfgPMC();
    // AT91F_PIO_CfgInput(AT91C_BASE_PIOA, (SW1|SW2));

   // Wait for the end of enumeration
   // while (!HID.IsConfigured(&HID));

    // InitMAM
    InitMMA();

    // InitADC
    ADCInit();

    // UART0 Init
    InitUSART0();

    // Stat led
    s_pPio->PIO_PER   = BIT31;
    // Configure PA31 as output
    s_pPio->PIO_OER   = BIT31;
    // Set PA31 to HIGH
    s_pPio->PIO_SODR  = BIT31;


    // Test flash
    if(TestFlash()) {

      for(i=0; i<20; i++) {
        s_pPio->PIO_CODR  = BIT31; Delay(150000);
        s_pPio->PIO_SODR  = BIT31; Delay(150000);
      }
    }

    // Button
    // Configure P20 as input
    s_pPio->PIO_ODR   = BIT20;
    // Enable
    s_pPio->PIO_PER   = BIT20;

    Delay(1000);

    // CALIBRATE WHEN BUTT IS PRESS
    // while((s_pPio->PIO_PDSR&BIT20)==BIT20);

    Delay(1000);

    // Get coordinates
    GetCoordinates();

    base_y = Coordinates[0]/NSAMPLE;
    base_x = Coordinates[1]/NSAMPLE;
    base_z = Coordinates[2]/NSAMPLE;


    // Start waiting some cmd
    while (1) {

      // Check enumeration
      if (HID.IsConfigured(&HID)) {

        // check button status
        if((s_pPio->PIO_PDSR&BIT20)==0) {

          // Set PA31 to LOW
          s_pPio->PIO_CODR  = BIT31;

          // set button flag
          button_flag = 0x01;

          Delay(1000);

        }
        else {

          // Set PA31 to HIGH
          // s_pPio->PIO_SODR  = BIT31;

          // clear button flag
          button_flag = 0x00;

        }


        GetCoordinates();

        Delay(10000);

//*        if((j++)==100) {
//*
//*         print_view = PRINT_COORDINATES;
//*         write_report_USART0();
//*
//*         // print_view = PRINT_DIVERSION;
//*         // write_report_USART0();
//*
//*         j=0;
//*        }

        y = 478 - Coordinates[0]/NSAMPLE;
        // y = base_y - Coordinates[0]/NSAMPLE;

        if(y>40) {
          if(y<50)
            HID.SendReport(&HID, button_flag, 0, -1);
          else if (y<100)
            HID.SendReport(&HID, button_flag, 0, -2);
          else if (y<150)
            HID.SendReport(&HID, button_flag, 0, -3);
          else if (y<200)
            HID.SendReport(&HID, button_flag, 0, -6);
          else
            HID.SendReport(&HID, button_flag, 0, -16);
        }
        else if(y<-40){
        if(y>-50)
            HID.SendReport(&HID, button_flag, 0, 1);
          else if (y>-100)
            HID.SendReport(&HID, button_flag, 0, 2);
          else if (y>-150)
            HID.SendReport(&HID, button_flag, 0, 3);
          else if (y>-200)
            HID.SendReport(&HID, button_flag, 0, 6);
          else
            HID.SendReport(&HID, button_flag, 0, 16);

        }

        x = 565 - Coordinates[1]/NSAMPLE;
        // x = base_x - Coordinates[1]/NSAMPLE;

        if(x>40) {
          if(x<50)
            HID.SendReport(&HID, button_flag, -1, 0);
          else if (x<100)
            HID.SendReport(&HID, button_flag, -2, 0);
          else if (x<150)
            HID.SendReport(&HID, button_flag, -3, 0);
          else if (x<200)
            HID.SendReport(&HID, button_flag, -6, 0);
          else
            HID.SendReport(&HID, button_flag, -16, 0);
        }
        else if(x<-40){
          if(x>-50)
            HID.SendReport(&HID, button_flag, 1, 0);
          else if (x>-100)
            HID.SendReport(&HID, button_flag, 2, 0);
          else if (x>-150)
            HID.SendReport(&HID, button_flag, 3, 0);
          else if (x>-200)
            HID.SendReport(&HID, button_flag, 6, 0);
          else
            HID.SendReport(&HID, button_flag, 16, 0);

        }

        // just test Z coordinate
        z = Coordinates[2]/NSAMPLE;

        if(z<300) {
          s_pPio->PIO_CODR  = BIT31;
        }
        else {
          s_pPio->PIO_SODR  = BIT31;
        }

        Delay(20);



//*      x = ((150) - GetADC4())/20;
//*      HID.SendReport(&HID, button, x, 0);
//*      Delay(50);
//*      HID.SendReport(&HID, button, ((base_y) - GetADC5())/50, 0);
//*      Delay(50);
//*      HID.SendReport(&HID, button, ((base_z) - GetADC6())/50, 0);
//*      Delay(50);
//*
//*       button = 0;
//*
//*       for(j=0; j<100; j++) {
//*           HID.SendReport(&HID, button, 1, 0);
//*           Delay(50);
//*       }
//*
//*       for(j=0; j<100; j++) {
//*           HID.SendReport(&HID, button, 0, 1);
//*           Delay(50);
//*       }
//*
//*       for(j=0; j<100; j++) {
//*         HID.SendReport(&HID, button, -1, 0);
//*         Delay(50);
//*       }
//*
//*       for(j=0; j<100; j++) {
//*         HID.SendReport(&HID, button, 0, -1);
//*         Delay(50);
//*       }

      }
   }
}
Beispiel #12
0
static void ReadOBJ(const char *filename) {
    FILE *fp = fopen(filename, "r");
     if (fp == NULL)
         sreFatalError("Could not open file %s.", filename);
    for (;;) {
        char *str = GetWords(fp);
        if (str == NULL)
            // End of file.
            break;
        RemoveComments();
        if (nu_words == 0)
            continue;
        int command = - 1;
        if (strcmp(words[0], "v") == 0)
           command = 0;
        else if (strcmp(words[0], "vn") == 0)
           command = 1;
        else if (strcmp(words[0], "vt") == 0)
           command = 2;
        else if (strcmp(words[0], "f") == 0)
           command = 3;
        if (command < 0)
            // First word not recognized.
            continue;
        if (command <= 2) {
           // Get up to four coordinates.
           float coord[4];
           int n = GetCoordinates(1, coord);
           if (command == 0)
               AddVertexAttribute(SRE_ATTRIBUTE_POSITION, coord, n);
           else if (command == 1)
               AddVertexAttribute(SRE_ATTRIBUTE_NORMAL, coord, n);
           else
               AddVertexAttribute(SRE_ATTRIBUTE_TEXCOORDS, coord, n);
        }
        else {
            // Face defition.
            BeginFace(4, SRE_POSITION_MASK | SRE_NORMAL_MASK | SRE_TEXCOORDS_MASK);
            for (int word_index = 1; word_index < nu_words; word_index++) {
                int vertex_index[3];
                DecodeOBJFaceIndices(words[word_index], vertex_index);
                for (int k = 0; k < 3; k++) {
                    // Special value INT_MAX means not used; AddFace expects - 1
                    // for unused attributes.
                    if (vertex_index[k] == INT_MAX)
                        vertex_index[k] = - 1;
                     else {
                        if (vertex_index[k] > 0)
                            // Regular index; counting starts at 1 in OBJ files.
                            vertex_index[k]--;
                        else if (vertex_index[k] < 0)
                            // Negative numer is relative index.
                            vertex_index[k] += nu_attribute_vertices[OBJ_attributes[k]];
                        else
                            ModelFileReadError("Vertex index of 0 not allowed in OBJ file");
                    }
                }
                AddFaceVertex(OBJ_attributes, vertex_index);
            }
            EndFace();
        }
    }
    fclose(fp);
}