AutodeskAILab / Fusion360GalleryDataset

Data, tools, and documentation of the Fusion 360 Gallery Dataset
Other
408 stars 49 forks source link

Reconstruction of disconnected shapes #72

Closed Bh4r4t closed 3 years ago

Bh4r4t commented 3 years ago

Hi,

Can I create graphs in PerFace mode using Regraph for 3D models which contain disconnected shapes? For example, the following model from the reconstruction dataset contains two separate components.

Though the above model gave an assertion error, is it possible for some other 3D models in the reconstruction dataset to generate a graph successfully?

karldd commented 3 years ago

Yes, graphs from regraph can have multiple bodies in them. They will be represented as disconnected parts of the graph. In the preprocessed data there are 56 graphs from 2+ bodies.

from pathlib import Path
import json

rg_dir = Path("path/to/preprocessed/regraph/data")
sequences = obj_files = [x for x in rg_dir.glob("*_sequence.json")]

two_body_count = 0
for sequence in sequences:
    with open(sequence, encoding="utf8") as f:
        json_data = json.load(f)
        if json_data["properties"]["body_count"] > 1:
            two_body_count += 1
            print(sequence.name)
print(two_body_count, "graphs with >1 bodies")

Which gives the output:

134381_b7f05dc3_0000_sequence.json
86381_dcef1ea4_0000_sequence.json
41473_c2137170_0026_sequence.json
133131_7990165e_0000_sequence.json
...
37340_fee2e667_0000_sequence.json
83400_6db148a7_0000_sequence.json
56 graphs with >1 bodies

You can use the regraph_viewer to visualize the graph.

Bh4r4t commented 3 years ago

Thanks for the quick reply! Yes, there are samples in the preprocessed data with more than one body. But I got an error while generating the graph from regraph for 134381_b7f05dc3_0000.json with PerFace mode.

Here is the output from regraph_results.json:

{
    "134381_b7f05dc3_0000.json": [
        {
            "status": "Exception",
            "exception": "AssertionError",
            "exception_args": "0.0 != 72.00200000000001 within 1 places (72.00200000000001 difference) : bounding_box_max_x",
            "trace": "Traceback (most recent call last):\n  File \"Fusion360GalleryDataset/tools/regraph/regraph_exporter.py\", line 107, in export\n    reconstruction=self.reconstruction\n  File \"Fusion360GalleryDataset\\tools\\common\\regraph.py\", line 865, in write\n    target=reconstruction\n  File \"Fusion360GalleryDataset\\tools\\common\\regraph.py\", line 964, in reconstruct\n    self.test_reconstruction(target, test_comp)\n  File \"Fusion360GalleryDataset\\tools\\common\\regraph.py\", line 1071, in test_reconstruction\n    places=places, msg=\"bounding_box_max_x\"\n  File \"AppData\\Local\\Autodesk\\webdeploy\\production\\9b292d8eef538636fb448307b89a33246e260a1a\\Python\\lib\\unittest\\case.py\", line 906, in assertAlmostEqual\n    raise self.failureException(msg)\nAssertionError: 0.0 != 72.00200000000001 within 1 places (72.00200000000001 difference) : bounding_box_max_x\n"
        }
    ]
}

Just to check, I again ran the same sample 134381_b7f05dc3_0000.json in regraph, and this time it ran successfully. Why did it happen?

karldd commented 3 years ago

Off the top of my head, this might happen if you have another file open (or some geometry) in Fusion 360. Do you think the first time you ran it and got the exception that could be the case?

Bh4r4t commented 3 years ago

No, I don't think so. I ran the script on a fresh start of fusion 360.

karldd commented 3 years ago

I'm not sure what is happening here to be honest. I can run it on my end and I get this output:

{
    "134381_b7f05dc3_0000.json": [
        {
            "status": "Success",
            "file": "134381_b7f05dc3_0000_0000.json"
        },
        {
            "status": "Success",
            "file": "134381_b7f05dc3_0000_0001.json"
        },
        {
            "status": "Success",
            "file": "134381_b7f05dc3_0000_0002.json"
        },
        {
            "status": "Success",
            "file": "134381_b7f05dc3_0000_0003.json"
        },
        {
            "status": "Success",
            "file": "134381_b7f05dc3_0000_0004.json"
        },
        {
            "status": "Success",
            "file": "134381_b7f05dc3_0000_0005.json"
        },
        {
            "status": "Success",
            "file": "134381_b7f05dc3_0000_0006.json"
        }
    ]
}

Having said that I don't doubt that an assertion error could be thrown. In my experience it can sometimes be due to the state within Fusion, but I don't have any specific advice on how to avoid this type of issue as it often is hard to reproduce.

karldd commented 3 years ago

Closing this for now, let me know if you have other issues with this.

Bh4r4t commented 3 years ago

Hi, From where are you importing adsk packages. Are these the definitions of procedures and classes provided by fusion 360 API?

karldd commented 3 years ago

Yes, those adsk packages are from the Fusion 360 API. You have to be running the python code from a Fusion 360 script/add-in to be able to use them as they rely on the underlying CAD software. Its unfortunately not possible to run them outside of the Fusion 360 environment.