Пример #1
0
void Maths_Contents::create_default_tangent_factors_1()
{
    unsigned int n = nodes_1_.size();
    tangent_factors_1_.resize(n);
    std::fill(tangent_factors_1_.begin(), tangent_factors_1_.end(), complex_number(0.25, 0.0));
    return;
}
void Canvas_Delegate_Riemann_Mapping::draw_background_image()
{
    QRect source(0, 0, image_width_, image_height_);
    complex_number left_top_corner, right_bottom_corner;
    int top, left, width, height;
    width = int_round(image_width_*scale_/(*image_scale_));
    height = int_round(image_height_*scale_/(*image_scale_));

    if (width > height)
    {
        left_top_corner = complex_number(-1.5, image_height_*0.5/(*image_scale_));
        right_bottom_corner = complex_number(1.5, -image_height_*0.5/(*image_scale_));
    }
    else
    {
        left_top_corner = complex_number(- image_width_*0.5/(*image_scale_), 1.5);
        right_bottom_corner = complex_number(image_width_*0.5/(*image_scale_), - 1.5);
    }
    integer_coordinates left_top_corner_in_pixels = complex_to_pixels_coordinates(left_top_corner);
    integer_coordinates right_bottom_corner_in_pixels = complex_to_pixels_coordinates(right_bottom_corner);

    //affine_transform_.set_for_match_triangles_in_pixels(&scale_, &origin_x_in_pixels_, &origin_y_in_pixels_,
    //            image_scale_, image_origin_x_in_pixels_, image_origin_y_in_pixels_);
    //affine_transform_.match_coordinates_in_pixels();
    //integer_coordinates left_top = affine_transform_.kick(left_top_corner_in_pixels);



    left = left_top_corner_in_pixels.first;
    top = left_top_corner_in_pixels.second;
    width = right_bottom_corner_in_pixels.first - left;
    height = right_bottom_corner_in_pixels.second - top;
    QRect target(left, top, width, height);
    /*std::cout << "width = " << width << ", "
                 << "height = " << height << ", "
                    << "top = " << top << ", "
                       << "left = " << left << ", "
                          << "ox = " << *image_origin_x_in_pixels_ << ", "
                          << "oy = " << *image_origin_y_in_pixels_ << std::endl;*/
    painter_->setOpacity(0.5);
    painter_->drawImage(target, *image_, source);
    painter_->setOpacity(1.0);
    return;
}
Пример #3
0
template <> Mobius Graph<Circle>::optimal_mobius() const
{
    complex_number z_k;
    double r_k, rho_k, cos_k, sin_k, b_k;
    double A = 0, S = 0, C = 0;

    unsigned int k;
    for (k=0; k<vertices_.size(); k++)
    {
        z_k = vertices_[k].content_.get_affix();
        r_k = vertices_[k].content_.get_radius();
        rho_k = abs(z_k);
        cos_k = real(z_k / rho_k);
        sin_k = imag(z_k / rho_k);
        b_k = rho_k/r_k;
        C += b_k * cos_k;
        S += b_k * sin_k;
        A += (rho_k*rho_k - r_k*r_k + 1.0)/r_k;
    }


    double theta = atan(S/C);
    double cos_theta = cos(theta);
    double sin_theta = sin(theta);

    double u = -(C*cos_theta + S*sin_theta);

    double B = 0.5*A/u;
    double discrim_reduit = B*B - 1;

    if (discrim_reduit < 0)
    {
        //std::cout << "ERROR in Graphe<Circle>::optimal_mobius(): negative discriminant!" << std::endl;
        return Mobius(complex_number(0.0, 0.0));
    }
    else
    {
        double rac = sqrt(discrim_reduit);
        double rho = -B - rac;
        return Mobius(complex_number(rho*cos_theta, rho*sin_theta));
    }
}
Пример #4
0
complex_number OceanSurface::h_t_0(int n, int m) {
	static std::random_device rd;
	static std::mt19937 generator(rd());
	static std::normal_distribution<float> distribution(0.0f, 1.0f);

	float e_r = distribution(generator);
	float e_i = distribution(generator);
	//e_r = 0.02f; e_i = 0.02f;

	return complex_number(e_r, e_i) * sqrt(phillips_spectrum(n, m) / 2.0f);
}
Пример #5
0
void Maths_Contents::initialize_curve_2(curve_choice_type curve_choice_flag_2, unsigned int nb_sides_2)
{
    nodes_2_.clear();

    switch(curve_choice_flag_2)
    {
    case CUSTOM:
        break;
    case RECTANGLE:
        nodes_2_.push_back(Point(complex_number(1.0, 1.0)));
        break;
    case POLYGON:
        nodes_2_.push_back(Point(complex_number(1.0, 0.0)));
        break;
    case STAR:
        initialize_star_2(nb_sides_2);
        break;
    case ELLIPSE:
        nodes_2_.push_back(Point(complex_number(1.0, 1.0)*(sqrt(2.0)/2.0)));
        break;
    case EPICYCLOID:
        nodes_2_.push_back(Point(complex_number((nb_sides_2*1.3)/(nb_sides_2 + 2), 0.0)));
        break;
    case KOCH:
        nodes_2_.push_back(Point(complex_number(1.0, 1.0/sqrt(3.0))));
        break;
    default:
        std::cout << "ERROR in Maths_Contents::initialize_curve_2: flag problem" << std::endl;
        throw(QString("ERROR in Maths_Contents::initialize_curve_2: flag problem"));
    }

    if (curve_choice_flag_2!=STAR)
    {
        curve_2_.create_curve(nodes_2_, tangent_factors_2_, curve_choice_flag_2, false, nb_sides_2, 0);
    }
    return;
}
Пример #6
0
void Canvas_Delegate_Tests::create_curve()
{
    std::vector<double> abscissa;
    std::vector<double> ordinates;

    double delta_min = deltas_.front();
    double delta_max = deltas_.back();
    unsigned int N = deltas_.size();

    double a = 2.5/(delta_max - delta_min);
    double b = -1.0 - a*delta_min;

    unsigned int i;
    for(i=0; i<N; i++)
    {
        abscissa.push_back(a*deltas_[i]+b);
    }

    double score_min = *min_element(overall_scores_.begin(), overall_scores_.end());
    double score_max = *max_element(overall_scores_.begin(), overall_scores_.end());

    a = 2.5/(score_max - score_min);
    b = -1.0 - a*score_min;
    for(i=0; i<N; i++)
    {
        ordinates.push_back(a*overall_scores_[i]+b);
    }

    curve_points_.clear();
    for(i=0; i<N; i++)
    {
        curve_points_.push_back(Point(complex_number(abscissa[i], ordinates[i])));
    }

    return;
}
void Canvas_Delegate_Riemann_Mapping::mouse_move_event()
{
    if (!click_on_)
    {
        set_node_point_under_mouse(point_under_mouse_);
    }

    if (beziers_mode() && !click_on_)
    {
        set_tangent_control_point_under_mouse(point_under_mouse_);
    }

    if ((!is_node_point_selected_) && (!is_tangent_control_point_selected_) &&
            (*draw_curve_flag_==DRAW_CURVE_INVALID
             || *draw_curve_flag_==DRAW_CURVE_READY || *draw_curve_flag_==DRAW_CURVE_DONE))
    {
        if ((*draw_2_curves_flag_==DRAW_2_CURVES_DONE || !shower_) &&
                (!click_on_ || QApplication::keyboardModifiers() == Qt::ControlModifier))
        {
            set_vertex_under_mouse(point_under_mouse_);
            set_vertex_highlighted(is_vertex_under_mouse_, index_vertex_under_mouse_);
        }

        if (*draw_2_curves_flag_==DRAW_2_CURVES_DONE && (!click_on_ || QApplication::keyboardModifiers() == Qt::ControlModifier))
        {
            if (left_canvas_)
            {
                window_->signal_received(VERTEX_HIGHLIGHTED_LEFT);
            }
            else
            {
                window_->signal_received(VERTEX_HIGHLIGHTED_RIGHT);
            }
        }
    }

    if (click_on_ && is_node_point_selected_)
    {
        (*nodes_)[node_point_selected_] = point_under_mouse_;
        curve_->create_curve(*nodes_, *tangent_factors_, *curve_choice_flag_, smooth_, nb_sides_, node_point_selected_);
    }
    else if (click_on_ && is_tangent_control_point_selected_
             && beziers_mode())
    {
        unsigned int i = tangent_control_point_selected_, N = nodes_->size();
        complex_number actual_tangent = point_under_mouse_.get_affix() - (*nodes_)[i].get_affix();
        complex_number default_tangent = (*nodes_)[(i+1)%N].get_affix() - (*nodes_)[(N+i-1)%N].get_affix();
        if (actual_tangent != complex_number(0.0, 0.0))
        {
            (*tangent_factors_)[i] = (1.0/default_tangent)*actual_tangent;
        }
        curve_->create_curve(*nodes_, *tangent_factors_, *curve_choice_flag_, smooth_, nb_sides_, node_point_selected_);
    }


    if (click_on_ && shower_ && *draw_2_curves_flag_==DRAW_2_CURVES_DONE)
    {
        if (curve_->is_inside(point_under_mouse_))
        {
            point_mouse_over_inverse_in_unit_disk_ = riemann_positions_->compute_inverse_image_in_unit_disk(
                        point_under_mouse_, search_tree_);
            if (norm(point_mouse_over_inverse_in_unit_disk_.get_affix())<1)
            {
                apply_mobius();
            }
        }
    }

    QString message;
    if (is_node_point_under_mouse_)
    {
        if (node_point_under_mouse_ == 0 && *draw_curve_flag_ == DRAW_CURVE_NODES && nodes_->size()>2)
        {
            message = QString("Click on this node to close the curve");

            *message_ = message;
            window_->signal_received(MESSAGE);
        }
        else if (!(*draw_curve_flag_ == DRAW_CURVE_NODES && node_point_under_mouse_+1 == nodes_->size()
                   && node_point_created_))
        {
            message = QString("Click and drag to move this node");

            *message_ = message;
            window_->signal_received(MESSAGE);
        }
    }
    else
    {
        node_point_created_ = false;
    }

    if (!is_node_point_under_mouse_ && is_tangent_control_point_under_mouse_ && beziers_mode())
    {
        message = QString("Click and drag to move this control point");

        *message_ = message;
        window_->signal_received(MESSAGE);
    }

    if (is_vertex_highlighted_ && !is_node_point_under_mouse_
            && !(is_tangent_control_point_under_mouse_ && beziers_mode()))
    {
        message = QString("Triangle n%1 %2")
                .arg(QChar(0x00B0))
                .arg(index_vertex_highlighted_ + 1);
        *message_ = message;
        window_->signal_received(MESSAGE);
    }

    if (!is_vertex_under_mouse_ && !is_node_point_under_mouse_ &&
            !(is_tangent_control_point_under_mouse_ && beziers_mode()))
    {
        window_->signal_received(MESSAGE, -1);
    }

    return;
}
void Canvas_Delegate_Riemann_Mapping::reset_canvas_delegate_for_computing()
{
    mobius_ = Mobius(complex_number(0.0, 0.0));
    reset_selected_stuff();
    return;
}
Пример #9
0
  complex_number complex_number::operator-(complex_number c) {
    return complex_number(a - c.a,
			  b - c.b);
  }
Пример #10
0
  complex_number complex_number::operator+(complex_number c) {
    return complex_number(a + c.a,
			  b + c.b);
  }
Пример #11
0
 Point(double x, double y) {affix_ = complex_number(x, y);}
Пример #12
0
void OceanSurface::updateOcean(float t) {
	if (!gpu) {

		for (int i = 0; i < N; i++) {
			float k_x = float(M_PI) * (2.0f * i - N) / L_x; // x-coordinate of wavevector at 'pos'

			for (int j = 0; j < M; j++) {
				int pos = i * M + j;

				float k_z = M_PI * (2.0f * j - M) / L_z; // z-coordinate of wavevector at 'pos'
				float k_length = sqrtf(k_x * k_x + k_z * k_z); // length of wavevector 'k'

				// calc all complex amplitudes in time t
				h_fft[pos] = h_t(i, j, t);

				// calc all displacements in time t
				if (k_length < 0.000001) { // ignore small wavevectors, put (0, 0) displacement
					dx_fft[pos] = complex_number();
					dz_fft[pos] = complex_number();
				}
				else { // calculate displacement via formula
					dx_fft[pos] = complex_number(0.0f, -k_x / k_length) * h_fft[pos];
					dz_fft[pos] = complex_number(0.0f, -k_z / k_length) * h_fft[pos];
				}

				// calc x-, and z- component of gradient of h_fft
				gradient_x[pos] = complex_number(0.0f, k_x) * h_fft[pos];
				gradient_z[pos] = complex_number(0.0f, k_z) * h_fft[pos];
			}
		}

		// row flipping
		/*/complex_number *h_fft_2 = new complex_number[N * N];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < M; j++) {
				int pos_1 = i * M + j;
				int pos_2 = (N - i - 1) * M + j;
				h_fft_2[pos_2] = h_fft[pos_1];
			}
		}*/
	} 
	else {

		// first update height map with time amplitudes (and displacement map with gradient map);
		glUseProgram(upd_height_program);

		glUniform1f(total_time_location, t);
		// height map
		glBindImageTexture(0, texture_H_t0, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RG32F);
		glBindImageTexture(1, texture_H_t0_cc, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RG32F);
		glBindImageTexture(2, texture_H_t, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RG32F);

		// displacement map
		glBindImageTexture(3, texture_Dx, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RG32F);
		glBindImageTexture(4, texture_Dz, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RG32F);

		// gradient map
		glBindImageTexture(5, texture_Gradx, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RG32F);
		glBindImageTexture(6, texture_Gradz, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RG32F);

		glDispatchCompute(N, N, 1);
		glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);

		glUseProgram(0);

		// fft in compute shader
		glUseProgram(fft_comp_program);

		// update texture
		/*glBindTexture(GL_TEXTURE_2D, texture_H_t);
		glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, N, N, GL_RG, GL_FLOAT, h_fft);
		//glTexImage2D(GL_TEXTURE_2D, 0, GL_RG32F, N, N, 0, GL_RG, GL_FLOAT, h_fft);
		glBindTexture(GL_TEXTURE_2D, 0);*/


		// bind reverse indices
		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, rev_ind_buffer);

		/*______________HEIGHT MAP FFT________________*/

		// fft per rows
		glUniform1i(fft_column_location, 0);
		glBindImageTexture(0, texture_H_t, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RG32F);
		glBindImageTexture(1, texture_H_fft_t_row, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RG32F);
		glDispatchCompute(1, N, 1);
		glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);

		// fft per columns
		glUniform1i(fft_column_location, 1);
		glBindImageTexture(0, texture_H_fft_t_row, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RG32F);
		glBindImageTexture(1, texture_H_fft_t_col, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RG32F);
		glDispatchCompute(1, N, 1);
		glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);

		/*______________DISPLACEMENT-X MAP FFT________________*/

		// fft per rows
		glUniform1i(fft_column_location, 0);
		glBindImageTexture(0, texture_Dx, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RG32F);
		glBindImageTexture(1, tex_dx_fft_row, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RG32F);
		glDispatchCompute(1, N, 1);
		glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);

		// fft per columns
		glUniform1i(fft_column_location, 1);
		glBindImageTexture(0, tex_dx_fft_row, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RG32F);
		glBindImageTexture(1, tex_dx_fft, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RG32F);
		glDispatchCompute(1, N, 1);
		glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);

		/*______________DISPLACEMENT-Z MAP FFT________________*/

		// fft per rows
		glUniform1i(fft_column_location, 0);
		glBindImageTexture(0, texture_Dz, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RG32F);
		glBindImageTexture(1, tex_dz_fft_row, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RG32F);
		glDispatchCompute(1, N, 1);
		glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);

		// fft per columns
		glUniform1i(fft_column_location, 1);
		glBindImageTexture(0, tex_dz_fft_row, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RG32F);
		glBindImageTexture(1, tex_dz_fft, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RG32F);
		glDispatchCompute(1, N, 1);
		glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);

		/*______________GRADIENT-X MAP FFT________________*/

		// fft per rows
		glUniform1i(fft_column_location, 0);
		glBindImageTexture(0, texture_Gradx, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RG32F);
		glBindImageTexture(1, tex_gradx_fft_row, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RG32F);
		glDispatchCompute(1, N, 1);
		glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);

		// fft per columns
		glUniform1i(fft_column_location, 1);
		glBindImageTexture(0, tex_gradx_fft_row, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RG32F);
		glBindImageTexture(1, tex_gradx_fft, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RG32F);
		glDispatchCompute(1, N, 1);
		glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);

		/*______________GRADIENT-Z MAP FFT________________*/

		// fft per rows
		glUniform1i(fft_column_location, 0);
		glBindImageTexture(0, texture_Gradz, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RG32F);
		glBindImageTexture(1, tex_gradz_fft_row, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RG32F);
		glDispatchCompute(1, N, 1);
		glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);

		// fft per columns
		glUniform1i(fft_column_location, 1);
		glBindImageTexture(0, tex_gradz_fft_row, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RG32F);
		glBindImageTexture(1, tex_gradz_fft, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RG32F);
		glDispatchCompute(1, N, 1);
		glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);

		glUseProgram(0);
	}

	int error = glGetError();
	if (error != GL_NO_ERROR) {
		int b = 4;
	}

	if (gpu) {
		return;
	}
	for (unsigned int i = 0; i < N; i++) { // horizontal fft for rows
		/*fft->fft(h_fft, h_fft, 1, i * M);
		fft->fft(dx_fft, dx_fft, 1, i * M);
		fft->fft(dz_fft, dz_fft, 1, i * M);
		fft->fft(gradient_x, gradient_x, 1, i * M);
		fft->fft(gradient_z, gradient_z, 1, i * M);*/
		myFFT->processVertical(h_fft, 1, i * M);
		myFFT->processVertical(dx_fft, 1, i * M);
		myFFT->processVertical(dz_fft, 1, i * M);
		myFFT->processVertical(gradient_x, 1, i * M);
		myFFT->processVertical(gradient_z, 1, i * M);
	}

	for (unsigned int j = 0; j < M; j++) { // vertical fft for columns
		/*fft->fft(h_fft, h_fft, M, j);
		fft->fft(dx_fft, dx_fft, M, j);
		fft->fft(dz_fft, dz_fft, M, j);
		fft->fft(gradient_x, gradient_x, M, j);
		fft->fft(gradient_z, gradient_z, M, j);*/
		myFFT->processHorizontal(h_fft, M, j);
		myFFT->processHorizontal(dx_fft, M, j);
		myFFT->processHorizontal(dz_fft, M, j);
		myFFT->processHorizontal(gradient_x, M, j);
		myFFT->processHorizontal(gradient_z, M, j);
	}

	
	glm::vec3 normal; // temp variable for normal calculation
	int sign;
	float signs[] = { 1.0f, -1.0f };
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			int pos = i * M + j;

			// flip sign for height
			sign = signs[(i + j) & 1];
			grid[pos].y = h_fft[pos].re * sign;

			// flip sign for displacement
			dx_fft[pos] = dx_fft[pos] * sign;
			dz_fft[pos] = dz_fft[pos] * sign;
			// then calc displacement for original position in grid
			//grid[pos].x = init_positions[pos].x + lambda * dx_fft[pos].re;
			//grid[pos].z = init_positions[pos].z + lambda * dz_fft[pos].re;

			// flip sign for gradient component;
			gradient_x[pos] = gradient_x[pos] * sign;
			gradient_z[pos] = gradient_z[pos] * sign;

			// then calculate normal of vertex and normalize it
			normal = glm::vec3(-gradient_x[pos].re, 1.0f, -gradient_z[pos].re);
			normal = glm::normalize(normal);
			// and save it to vertex structure
			grid[pos].normal_x = normal.x;
			grid[pos].normal_y = normal.y;
			grid[pos].normal_z = normal.z;
		}
	}
}