Sie sind nicht angemeldet.

nautama

Schüler

  • »nautama« ist der Autor dieses Themas

Beiträge: 82

Wohnort: La Paz, Baja California Sur, México

Beruf: KRpano programmer at www.imagen360.com

  • Nachricht senden

1

Freitag, 3. Oktober 2014, 18:45

Help With a Category Counter!

Hello everyone. I'm trying to build an action that can, from a list of scenes (each one with a category="something" or "null" variable), know how many categories there are in the list, create new variables for every type of category and within those variables count how many of each category there are. I'll give you an example:

FROM THE LIST:
<scene name="0" category="null"/>
<scene name="1" category="A"/>
<scene name="2" category="B"/>
<scene name="3" category="A"/>
<scene name="4" category="A"/>
<scene name="5" category="A"/>
<scene name="6" category="C"/>
<scene name="7" category="B"/>

In the end the action would have to create these variables with these values (Note that I wish the action to create the variables without me having to tell it which categories there are, and that the order of the scenes is irrelevant):

A="4" B="2" C="1"

I've been trying to build it with a for action but so far I have been unsuccessful, ¿any ideas?

Beiträge: 1 857

Beruf: Virtual Tours - Photography - Krpano developer

  • Nachricht senden

2

Freitag, 3. Oktober 2014, 21:02

Hello everyone. I'm trying to build an action that can, from a list of scenes (each one with a category="something" or "null" variable), know how many categories there are in the list, create new variables for every type of category and within those variables count how many of each category there are. I'll give you an example:

FROM THE LIST:
<scene name="0" category="null"/>
<scene name="1" category="A"/>
<scene name="2" category="B"/>
<scene name="3" category="A"/>
<scene name="4" category="A"/>
<scene name="5" category="A"/>
<scene name="6" category="C"/>
<scene name="7" category="B"/>

In the end the action would have to create these variables with these values (Note that I wish the action to create the variables without me having to tell it which categories there are, and that the order of the scenes is irrelevant):

A="4" B="2" C="1"

I've been trying to build it with a for action but so far I have been unsuccessful, ¿any ideas?


Quellcode

1
2
3
4
5
6
7
8
9
10
11
<action name="set_param">
		for(sub(i,%1.count,1), i GE 0, dec(i), 
			if(%1[get(i)].%2 == %3,
				copy(category[%4].count, i);
			);
		);
</action>
set_param(scene,category,A); 
trace(category[A].count);
trace(category[B].count);
trace(category[C].count);


Try something like that.
KRPano Developer: Portfolio ::Gigapixel Tagging Solutions - Porfolio 2 :: Facebook :: Twitter :: reddit.com/r/VirtualTour

3

Freitag, 3. Oktober 2014, 21:49

Hi! I love little challenges like this so here is my take:

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
<action name="get_categories">
  for(set(i,0), i LT scene.count, inc(i),
    if(get(scene[get(i)].category), 
      inc(get(scene[get(i)].category));
    ,
      set(get(scene[get(i)].category), 1);
    );
  );
  trace("a ", a);
  trace("b ", b);
  trace("c ", c);
</action>

Cheers,
Hernán
My Krpano plugins: Auto Thumbs - Tooltip - Abs

nautama

Schüler

  • »nautama« ist der Autor dieses Themas

Beiträge: 82

Wohnort: La Paz, Baja California Sur, México

Beruf: KRpano programmer at www.imagen360.com

  • Nachricht senden

4

Samstag, 4. Oktober 2014, 00:52

Woooooow, I thank you both for taking the time to help me, I tried Sachagriffin's suggestion but I wasn't able to make it work, and also I was confused by the %4 argument, probably I should have jiggled it more. Hernan's reply works wonderfully and is an exquisite piece of code. I had given up on that, I was making it work but with a different scene arrangement:

<scene name="0" category="A"/>
<scene name="1" category="A"/>
<scene name="2" category="A"/>
<scene name="3" category="B"/>
<scene name="4" category="B"/>
<scene name="5" category="B"/>
<scene name="6" category="C"/>
<scene name="7" category="C"/>

Which is not exactly what I wanted. Hernan, I don't wear a hat but if I did it would go take it off for you.

Thanks!

5

Samstag, 4. Oktober 2014, 02:08

Challenge accepted. We should have more of this brain trainings. I'm sure this would help us all being better or?
If you don't want to know the categories than I propose very similar approach but storing the results and reading them later on.

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<action name="report_categories">
  for(set(i,0), i LT scene.count, inc(i),  
    if(category[get(scene[get(i)].category)].sum, 
      inc(category[get(scene[get(i)].category)].sum);
    ,
      set(category[get(scene[get(i)].category)].sum, 1);
    );
  ); 
  for(set(i,0), i LT category.count, inc(i),trace(category[get(i)].name,': ',category[get(category[get(i)].name)].sum););  
</action>

<scene name="0" category="X"/>
<scene name="1" category="A"/>
<scene name="2" category="B"/>
<scene name="3" category="A"/>
<scene name="4" category="A"/>
<scene name="5" category="A"/>
<scene name="6" category="C"/>
<scene name="7" category="B"/>
<scene name="8" category="D"/>
<scene name="9" category="D"/>

x: 1
a: 4
b: 2
c: 1
d: 2

6

Samstag, 4. Oktober 2014, 21:58

Thank you for the kind words! I'm glad it helped.

Upon seeing it now I realized that it could be more even more succinct, and to keep it DRY, by putting "scene[get(i)].category" in a variable. Like:

Quellcode

1
2
3
4
5
6
7
8
  for(set(i,0), i LT scene.count, inc(i),
    copy(current, scene[get(i)].category); 
    if(get(current), 
      inc(get(current));
    ,
      set(get(current), 1);
    );
  );

I also like Umalo's suggestion to store them somewhere if you don't know them firsthand, but that really depends on the problem you're trying to solve.

Cheers *thumbsup*
My Krpano plugins: Auto Thumbs - Tooltip - Abs

nautama

Schüler

  • »nautama« ist der Autor dieses Themas

Beiträge: 82

Wohnort: La Paz, Baja California Sur, México

Beruf: KRpano programmer at www.imagen360.com

  • Nachricht senden

7

Montag, 6. Oktober 2014, 23:22

Thank you very much, guys, your suggestions have helped me a great deal. Now I'm facing a new dilemma and hopefully you'll still want to lend me a hand, I think I should have mentioned that what I'm after is no easy thing to achieve, I believe, but I'm still learning anyway.

So I've used the basic code you gave me to generate automatically a container layer for each of the categories in the list, now I'm on a mission to fill those containers with layers pertaining to the scenes in each category. I actually think I have that done already:

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
for(set(i,0);, i LT scene.count, inc(i);,
	        if(get(scene[get(i)].cat), 
			inc(get(scene[get(i)].cat));
		,
			set(get(scene[get(i)].cat), 1);
			
			txtadd(container_scrollarea,'container_',get(scene[get(i)].cat));
			addlayer(get(container_scrollarea));
			layer[get(container_scrollarea)].loadstyle(style_container_cat);	
		);
	);
	
  <!--AFTER GENERATING THE CONTAINERS, IT RUNS A NEW LOOP AND ASSIGNS THE LAYERS OF EACH SCENE TO THEM (BUTTONS)-->
  
	for(set(i,0);, i LT scene.count, inc(i);,
			
		 txtadd(scrollarea_button, get(scene[get(i)].cat),'_',get(scene[get(i)].name),'_button');
		 addlayer(get(scrollarea_button));
		 layer[get(scrollarea_button)].loadstyle(textstyle_bar_escenas);
		 set(layer[get(scrollarea_button)].html,get(scene[get(i)].title));
		
		txtadd(container_cat,'container_',get(scene[get(i)].cat));
		set(layer[get(scrollarea_button)].parent,get(container_cat));
		
	);


So this way I'm successfully (I think) putting each of the layers in their corresponding container. The issue here is that I would like the scene layers (buttons) to have an increasing Y-offset, so they're not all cramped up in one place, but this increase should depend on the category of the scene. This is the part where I don't know exactly how to make it work, I think I could use the

Quellcode

1
2
3
			inc(get(scene[get(i)].cat));
		,
			set(get(scene[get(i)].cat), 1);
.

part, replacing the 1 with the Y offset I want and then reading it and assigning it to each layer, but I have tried to do so unsuccessfully.

Any (other) ideas?

Alberto.

8

Dienstag, 7. Oktober 2014, 01:03

Can you share the complete code with us to play with?

nautama

Schüler

  • »nautama« ist der Autor dieses Themas

Beiträge: 82

Wohnort: La Paz, Baja California Sur, México

Beruf: KRpano programmer at www.imagen360.com

  • Nachricht senden

9

Dienstag, 7. Oktober 2014, 17:25

Sure!, I have a complete mess with my code, let me try to arrange it so you don't get lost! I'll try to post it today or tomorrow.

nautama

Schüler

  • »nautama« ist der Autor dieses Themas

Beiträge: 82

Wohnort: La Paz, Baja California Sur, México

Beruf: KRpano programmer at www.imagen360.com

  • Nachricht senden

10

Donnerstag, 9. Oktober 2014, 23:11

I decided to try a bit more to see if I could fix it myself and fortunately I did (still there's so much to work in), thank you very much everyone!

I'll post the final results when I get it done.

Alberto.