示例#1
0
double Geo3d_Ellipse_Point_Distance(const Geo3d_Ellipse *ellipse,
				    const double *pt)
{
  coordinate_3d_t tmp_pt;
  tmp_pt[0] = pt[0] - ellipse->center[0];
  tmp_pt[1] = pt[1] - ellipse->center[1];
  tmp_pt[2] = pt[2] - ellipse->center[2];
  
  if (ellipse->alpha != 0.0) {
    Rotate_Z((double*) tmp_pt, tmp_pt, 1, ellipse->alpha, 1);
  }

  if ((ellipse->orientation[0] != 0.0) || (ellipse->orientation[1] != 0.0)) {
    Rotate_XZ(tmp_pt, tmp_pt, 1, 
	      ellipse->orientation[0], ellipse->orientation[1], 1);
  }

  double d = 0.0;
  if (Point_In_Ellipse(tmp_pt[0], tmp_pt[1],
		       ellipse->radius * ellipse->scale, ellipse->radius)
      == FALSE) {
    d = Ellipse_Point_Distance(tmp_pt[0], tmp_pt[1],
			       ellipse->radius * ellipse->scale, 
			       ellipse->radius, NULL, NULL);
  }

  return sqrt(d * d + tmp_pt[2] * tmp_pt[2]);
}
示例#2
0
Geo3d_Scalar_Field* Neuroseg_Field_Sp(const Neuroseg *seg,
				      Neuroseg_Field_f field_func,
				      Geo3d_Scalar_Field *field)
{
  if ((seg->r1 == 0) || (seg->scale == 0)) {
    return NULL;
  }

  int nslice = NEUROSEG_DEFAULT_H;

  if (field == NULL) {
    field = New_Geo3d_Scalar_Field();
    Construct_Geo3d_Scalar_Field(field, NEUROSEG_SLICE_FIELD_LENGTH * nslice);
  }

  double z_start = 0.0;
  //double z_step = seg->h / nslice;
  double z_step = (seg->h - 1.0) / (nslice - 1);
  int length;
  coordinate_3d_t *points = field->points;
  double *values = field->values;
  double coef = NEUROSEG_COEF(seg) * z_step;
  double r = seg->r1;
  double z = z_start;

  field->size = 0;

  int j;
  for (j = 0; j < nslice; j++) {
    Neuroseg_Slice_Field_P(points, values, &length, field_func);
    int i;
    double weight = 0.0;
    for (i = 0; i < length; i++) {
      points[i][0] *= r * seg->scale;
      points[i][1] *= r;
      points[i][2] = z;
      weight += fabs(values[i]);
    }
    for (i = 0; i < length; i++) {
      values[i] /= weight;
    }
    z += z_step;
    r += coef;
    points += length;
    values += length;
    field->size += length;
  }


  if (seg->alpha != 0.0) {
    Rotate_Z(Coordinate_3d_Double_Array(field->points),
	     Coordinate_3d_Double_Array(field->points),
	     field->size, seg->alpha, 0);
  }

  if (seg->curvature >= NEUROSEG_MIN_CURVATURE) {
    double curvature = seg->curvature;
    if (curvature > NEUROSEG_MAX_CURVATURE) {
      curvature = NEUROSEG_MAX_CURVATURE;
    }

    Geo3d_Point_Array_Bend(field->points, field->size, seg->h / curvature);
  }

  if ((seg->theta != 0.0) || (seg->psi != 0.0)) {
    Rotate_XZ((double *)field->points, (double *)field->points, field->size, 
	      seg->theta, seg->psi, 0);
  }

  return field;
}
示例#3
0
Geo3d_Scalar_Field* Neuroseg_Field_Z(const Neuroseg *seg, double z, double step,
				     Geo3d_Scalar_Field *field)
{
  if ((seg->r1 == 0) || (seg->scale == 0)) {
    return NULL;
  }

  if (field == NULL) {
    field = New_Geo3d_Scalar_Field();
    Construct_Geo3d_Scalar_Field(field, NEUROSEG_SLICE_FIELD_LENGTH);
  }

  int length;
  coordinate_3d_t *points = field->points;
  double *values = field->values;
  /* double coef = (seg->r2 - seg->r1) / seg->h; */
  double coef = NEUROSEG_COEF(seg);
  double r = seg->r1 + coef * z;

  Neuroseg_Slice_Field(points, values, &length, NULL);
  
  field->size = length;

  int i;
  double weight = 0.0;
  double r_scale = r * seg->scale;
  double sqrt_r = sqrt(r);
  double sqrt_r_scale = sqrt_r * sqrt(sqrt(seg->scale));
  for (i = 0; i < length; i++) {
    neuroseg_scale_field(points[i], values + i, r, seg->scale, r_scale,
			 sqrt_r, sqrt_r_scale);
    points[i][2] = z;
    weight += fabs(values[i]);
  }

  for (i = 0; i < length; i++) {
    values[i] /= weight;
  }

  if (seg->alpha != 0.0) {
    Rotate_Z(Coordinate_3d_Double_Array(field->points),
    	     Coordinate_3d_Double_Array(field->points),
    	     field->size, seg->alpha, 0);
  }

  if (seg->curvature >= NEUROSEG_MIN_CURVATURE) {
    double curvature = seg->curvature;
    if (curvature > NEUROSEG_MAX_CURVATURE) {
      curvature = NEUROSEG_MAX_CURVATURE;
    }

    Geo3d_Point_Array_Bend(field->points, field->size, seg->h / curvature);
  }

  if ((seg->theta != 0.0) || (seg->psi != 0.0)) {
    Rotate_XZ((double *)field->points, (double *)field->points, field->size, 
	      seg->theta, seg->psi, 0);
  }

  return field;
}
示例#4
0
Geo3d_Scalar_Field* Neuroseg_Field_S(const Neuroseg *seg,
				     Neuroseg_Field_f field_func,
				     Geo3d_Scalar_Field *field)
{
  if ((seg->r1 == 0) || (seg->scale == 0)) {
    return NULL;
  }

  //int nslice = (int) round(seg->h);
  //int nslice = NEUROSEG_DEFAULT_H;
  int nslice = NEUROSEG_DEFAULT_H;
  /*
  if (nslice == 0) {
    nslice = 1;
  }
  */
  if (field == NULL) {
    field = New_Geo3d_Scalar_Field();
    //Neuroseg_Field_Point_Number(seg, step);
    Construct_Geo3d_Scalar_Field(field, NEUROSEG_SLICE_FIELD_LENGTH * nslice);
				 //Neuroseg_Field_Point_Number(seg, step));
  }

  /*
  Neuroseg_Field(seg, step, Coordinate_3d_Double_Array(field->points), 
		 field->values, &(field->size));
  */

  double z_start = 0.0;
  double z_step = (seg->h - 1.0) / (nslice - 1);
  //double z_step = (seg->h - 1.0) / nslice;
  //double z_step = seg->h / nslice;
  
  //double z_end = nslice;
  int length;
  coordinate_3d_t *points = field->points;
  double *values = field->values;
  double coef = NEUROSEG_COEF(seg) * z_step;
  double r = seg->r1;
  double z = z_start;

  Neuroseg_Slice_Field(points, values, &length, field_func);
  field->size = length;

  int i, j;
  double weight = 0.0;
  double r_scale = r * seg->scale;
  double sqrt_r = sqrt(r);
  double sqrt_sqrt_scale = sqrt(sqrt(seg->scale));
  double sqrt_r_scale = sqrt_r * sqrt_sqrt_scale;
  for (j = 1; j < nslice; j++) {
    z += z_step;
    if (coef != 0.0) {
      r += coef;
      r_scale = r * seg->scale;
      sqrt_r = sqrt(r);
      sqrt_r_scale = sqrt_r * sqrt_sqrt_scale;
    }
    points += length;
    values += length;
    field->size += length;    

    memcpy(points, field->points, sizeof(coordinate_3d_t) * length);
    memcpy(values, field->values, sizeof(double) * length);
    weight = 0.0;
    for (i = 0; i < length; i++) {
      points[i][2] = z;
      neuroseg_scale_field(points[i], values + i, r, seg->scale, r_scale,
			   sqrt_r, sqrt_r_scale);
      weight += fabs(values[i]);
      //weight += values[i] * values[i];
    }
    for (i = 0; i < length; i++) {
      //values[i] /= sqrt(weight);
      values[i] /= weight;
    }
  }

  points = field->points;
  values = field->values;
  r = seg->r1;
  r_scale = r * seg->scale;
  sqrt_r = sqrt(r);
  sqrt_r_scale = sqrt_r * sqrt_sqrt_scale;
  weight = 0.0;
  for (i = 0; i < length; i++) {
    points[i][2] = z_start;
    neuroseg_scale_field(points[i], values + i, r, seg->scale, r_scale,
			 sqrt_r, sqrt_r_scale);
    weight += fabs(values[i]);
    //weight += values[i] * values[i];
  }
  for (i = 0; i < length; i++) {
    values[i] /= weight;
    //values[i] /= sqrt(weight);
  }
  
  
  if (seg->alpha != 0.0) {
    Rotate_Z(Coordinate_3d_Double_Array(field->points),
	     Coordinate_3d_Double_Array(field->points),
	     field->size, seg->alpha, 0);
  }

  if (seg->curvature >= NEUROSEG_MIN_CURVATURE) {
    double curvature = seg->curvature;
    if (curvature > NEUROSEG_MAX_CURVATURE) {
      curvature = NEUROSEG_MAX_CURVATURE;
    }

    Geo3d_Point_Array_Bend(field->points, field->size, seg->h / curvature);
  }

  if ((seg->theta != 0.0) || (seg->psi != 0.0)) {
    Rotate_XZ(Coordinate_3d_Double_Array(field->points), 
	      Coordinate_3d_Double_Array(field->points),
	      field->size, seg->theta, seg->psi, 0);
  }

  return field;
}
LRESULT CALLBACK WndProc(	HWND	hWnd,			// Handle For This Window
							UINT	uMsg,			// Message For This Window
							WPARAM	wParam,			// Additional Message Information
							LPARAM	lParam)			// Additional Message Information
{
	switch (uMsg)									// Check For Windows Messages
	{
		case WM_ACTIVATE:							// Watch For Window Activate Message
		{
			if (!HIWORD(wParam))					// Check Minimization State
			{
				active=TRUE;						// Program Is Active
			}
			else
			{
				active=FALSE;						// Program Is No Longer Active
			}

			return 0;								// Return To The Message Loop
		}

		case WM_SYSCOMMAND:							// Intercept System Commands
		{
			switch (wParam)							// Check System Calls
			{
				case SC_SCREENSAVE:					// Screensaver Trying To Start?
				case SC_MONITORPOWER:				// Monitor Trying To Enter Powersave?
				return 0;							// Prevent From Happening
			}
			break;									// Exit
		}

		case WM_CLOSE:								// Did We Receive A Close Message?
		{
			PostQuitMessage(0);						// Send A Quit Message
			return 0;								// Jump Back
		}

		case WM_KEYDOWN:							// Is A Key Being Held Down?
		{
			keys[wParam] = TRUE;					// If So, Mark It As TRUE
			return 0;								// Jump Back
		}

		case WM_KEYUP:								// Has A Key Been Released?
		{
			keys[wParam] = FALSE;					// If So, Mark It As FALSE
			return 0;								// Jump Back
		}

		case WM_SIZE:								// Resize The OpenGL Window
		{
			ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));  // LoWord=Width, HiWord=Height
			return 0;								// Jump Back
		}

		// 此回调函数在Timer1控制下每10ms进行一次魔方旋转微调
		case WM_TIMER:
		{
			if(rotAngle != 0)
			{
				if(rotZ)
				{
					Rotate_Z();
				}

				if(rotY)
				{
					Rotate_Y();
				}

				if(rotX)
				{
					Rotate_X();
				}
			
			}
			
		}
	}

	// Pass All Unhandled Messages To DefWindowProc
	return DefWindowProc(hWnd,uMsg,wParam,lParam);
}