Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6642011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:52:46+00:00 2026-05-25T23:52:46+00:00

This is a cgal related question, but I think it is also a general

  • 0

This is a cgal related question, but I think it is also a general C++ question, so I ask it here.

I am trying to use the Alpha_shape_2 class, and assign it to AlphaShapeCg class in a subroutine named GetAlphaShalCg. The problem is that some of the function in Alpha_shape_2 doesn’t return correct result.

This is my code, it’s really simple, but I don’t quite know why there is a difference between assigning the Alpha_shape_2 to a wrapper in a subroutine, and then access the member in parent routine and accessing Alpha_shape_2 directly.

Here’s the complete code that you can compile and play with, if you have CGAL installed.

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/algorithm.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Alpha_shape_2.h>

#include <iostream>
#include <fstream>
#include <vector>
#include <list>


typedef CGAL::Exact_predicates_inexact_constructions_kernel K;

typedef K::FT FT;

typedef K::Point_2  Point;
typedef K::Segment_2  Segment;


typedef CGAL::Alpha_shape_vertex_base_2<K> Vb;
typedef CGAL::Alpha_shape_face_base_2<K>  Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> Tds;
typedef CGAL::Delaunay_triangulation_2<K,Tds> Triangulation_2;

typedef CGAL::Alpha_shape_2<Triangulation_2>  Alpha_shape_2;


template <class OutputIterator>
bool
file_input(OutputIterator out)
{
  std::ifstream is("./data/fin", std::ios::in);

  if(is.fail()){
    std::cerr << "unable to open file for input" << std::endl;
    return false;
  }

  int n;
  is >> n;
  std::cout << "Reading " << n << " points from file" << std::endl;
  CGAL::copy_n(std::istream_iterator<Point>(is), n, out);

  return true;
}

//------------------ main -------------------------------------------


struct AlphaShapeCg
{

    Alpha_shape_2 *AlphaShape;
};

void GetAlphaShalCg(AlphaShapeCg *ashape,  std::list<Point> points)
{

      Alpha_shape_2 A(points.begin(), points.end(),
          FT(100000),
          Alpha_shape_2::GENERAL);
    ashape->AlphaShape=&A;
}



int main()
{
  std::list<Point> points;
  if(! file_input(std::back_inserter(points))){
    return -1;
  }

   AlphaShapeCg ashape;


   GetAlphaShalCg(&ashape, points);

   Alpha_shape_2 *APtrs=(ashape.AlphaShape);
   int alphaEigenValue = APtrs->number_of_alphas(); // gives incorrect result; alphaEigenValue=0

  //Alpha_shape_2 A(points.begin(), points.end(),
  //  FT(100000),
  //  Alpha_shape_2::GENERAL);
  //   int alphaEigenValue = APtrs->number_of_alphas(); // gives correct result; alphaEigenValue!=0

}

Update: I tried to use

Alpha_shape_2 =new A(points.begin(), points.end(), FT(100000), Alpha_shape_2::GENERAL);

But this code simply won’t compile because of this error:

error C2513: ‘CGAL::Alpha_shape_2’ : no variable declared before
‘=’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:52:46+00:00Added an answer on May 25, 2026 at 11:52 pm

    You’re assigning a pointer to a local variable that gets destroyed when you exit the function.

    If you want to create the object in the function and return its address – you should use dynamic allocation (new it, don’t forget to delete when you’re done with it).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is related to hooking with Mobile Substrate, but as long as you
I'm trying to build CGAL for windows to use in my project under Visual
I am trying to add a color variable (unsigned char) to CGAL's Point_3 class
This might be a silly question but it just popped up in my mind.
I am trying to use CGAL on OS X 10.7 with Eclipse. I installed
This question was posted on StackApps , but the issue may be more a
This is a pretty simple question, and I searched the previous questions but couldn't
This may be an unusual question, but are there any resources people have come
This might seem like a stupid question I admit. But I'm in a small
This is a difficult and open-ended question I know, but I thought I'd throw

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.